
2、adodc的属性里,设置
a)连接数据库,可使用字符串方式(microsoft
jet
3.51
ole
db),access文件
b)记录源,cmdtext,满足条件的sql语句。
3、设置datagrid的属性:
c)datasourse设置为adodc1
4、打印可以考虑execl
菜单-》工程-》引用-》excel打钩
参考打印代码
Dim
xlBook
As
Excel.Workbook
Dim
xlSheet
As
Excel.Worksheet
Dim
xlApp
As
Excel.Application
Dim
strSource,
strDestination
As
String
Dim
i
As
Integer
Dim
j
As
Integer
cmdPrint.Enabled
=
False
Screen.MousePointer
=
vbHourglass
Set
xlApp
=
New
Excel.Application
Set
xlApp
=
CreateObject("Excel.Application")
'xlApp.Visible
=
False
strSource
=
App.Path
&
"\newtable.xls"
strDestination
=
App.Path
&
"\Temp.xls"
On
Error
GoTo
COPYERR
FileCopy
strSource,
strDestination
On
Error
GoTo
0
Set
xlBook
=
xlApp.Workbooks.Open(strDestination)
If
bTest
Then
Set
xlSheet
=
xlBook.Worksheets(5)
Else
Set
xlSheet
=
xlBook.Worksheets(3)
End
If
If
msgData.Rows
>
3
Then
xlSheet.Cells(1,
1)
=
lblTitle
xlSheet.Cells(2,
1)
=
lbl1(0)
For
i
=
2
To
Datagrid.Rows
-
1
For
j
=
0
To
Datagrid.Cols
-
1
xlSheet.Cells(i
+
3,
j
+
1)
=
Datagrid.TextMatrix(i,
j)
Next
j
Next
i
xlBook.Save
If
bPrint
Then
xlSheet.PrintOut
End
If
xlApp.Quit
Screen.MousePointer
=
vbArrow
cmdPrint.Enabled
=
True
Exit
Sub
COPYERR:
MsgBox
Err.Description
Screen.MousePointer
=
vbArrow
cmdPrint.Enabled
=
True
1、打开代码窗口,添加引用:Imports System.Data.SqlClient。
2、输入以下代码:
“Public conn1 As SqlConnection = New SqlConnection _
("server=192.168.1.79Initial Catalog= studentUser ID= panqePWD=shentai768@")”,vb就已经成功连接sql数据库了。
3、代码详解:声明关键字Public(因为是全局变量,所以用Public 来声明)。
4、连接参数。
5、如果SQL 数据库就在本机,则用以下代码连接:
("server=.Integrated Security=FalseInitial Catalog= studentUser ID= panqePWD=shentai768@")。
6:如果代码太长,影响可读性,可以用空格加"_"后,回车换行。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)