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
通过Adodc控件连接加密的数据库的方法有两种:一种方法是在设计状态时,在“属性窗口”中,对Adodc控件的ConnectionString属性设置一个有效的连接字符串,并在连接字符串后增加上”
Jet
OLEDB:
DataBase
password=1234”,再设置Adodc控件的CommandType、RecordSource的属性就可以创建到加密的数据库的连接了。
另一种方法是在运行时,通过代码动态地设置ConnectionString、CommandType和RecordSource属性来创建连接。
只要在ConnectionString属性的有效连接字符串后增加上”
Jet
OLEDB:
DataBase
password=1234”即可。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)