向各位前辈请教一下:
我在ACCESS中创建了一个表kehu,里面就两个字段:company_name和beizhu
在VB中建了一个窗体frmEmpInfo2用来查询客户信息,我用的是模糊查询,想通过模糊查询company_name,把ACCESS中的beizhu信息返回到datagrid中,但是我的程序运行后就是不在datagrid中显示,而是另跳出一个提示框显示备注信息,请高手们指教一下。谢谢!
Option ExplicitDim strsql As StringDim rs As New ADODB.RecordsetDim objscore As Recordset '保存客户信息Dim conn As RecordsetDim objcn As Connection '建立和保存数据库联接Dim i As Integer
==========================================================
'清除
Private Sub cmdClear_Click() Unload Me
End Sub
===============================================
'打印
Private Sub cmdPrint_Click()
If objscore.RecordCount < 1 Then Exit Sub
With objscore
.MoveFirst
strMsg = "" & objscore.Fields("备注")
End With
frmPrint.Show
frmPrint.Caption = "打印客户信息"
frmPrint.Print
frmPrint.Print
frmPrint.Print
frmPrint.Print strMsg
End Sub
=============================================
'查询
Private Sub Command1_Click()Dim Link As New ADODB.ConnectionDim rs As New ADODB.RecordsetLink.CursorLocation = adUseClientLink.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=ACCESS\kehu.mdb;Persist Security Info=False"Link.Openrs.Open "Select * From kehu Where company_name like '%" & txtCompany.Text & "%'", Link, adOpenDynamic, adLockOptimisticIf rs.RecordCount > 0 Then '填写数据
MsgBox rs.Fields("beizhu").Value
Else MsgBox "没有这个记录!"
End IfEnd Sub========================
Private Sub Form_Load()Dim DTbase As StringDTbase = App.Path + "\access\kehu.mdb"Set objcn = New ConnectionWith objcn
.Provider = "Microsoft.Jet.OLEDB.4.0"
.CursorLocation = adUseClient
.Open DTbase
End With
'建立数据库联接
Set conn = New RecordsetWith conn Set .ActiveConnection = objcn
.CursorLocation = adUseClient
.CursorLocation = adUseClient
.LockType = adLockOptimistic
'获取客户备注信息End WithSet flexshow.DataSource = objscore
'设置列数
flexshow.Cols = 1
'列标题 flexshow.TextMatrix(0, 0) = "备注"
'设置列宽
flexshow.ColWidth(0) = 2000End Sub
我在ACCESS中创建了一个表kehu,里面就两个字段:company_name和beizhu
在VB中建了一个窗体frmEmpInfo2用来查询客户信息,我用的是模糊查询,想通过模糊查询company_name,把ACCESS中的beizhu信息返回到datagrid中,但是我的程序运行后就是不在datagrid中显示,而是另跳出一个提示框显示备注信息,请高手们指教一下。谢谢!
Option ExplicitDim strsql As StringDim rs As New ADODB.RecordsetDim objscore As Recordset '保存客户信息Dim conn As RecordsetDim objcn As Connection '建立和保存数据库联接Dim i As Integer
==========================================================
'清除
Private Sub cmdClear_Click() Unload Me
End Sub
===============================================
'打印
Private Sub cmdPrint_Click()
If objscore.RecordCount < 1 Then Exit Sub
With objscore
.MoveFirst
strMsg = "" & objscore.Fields("备注")
End With
frmPrint.Show
frmPrint.Caption = "打印客户信息"
frmPrint.Print
frmPrint.Print
frmPrint.Print
frmPrint.Print strMsg
End Sub
=============================================
'查询
Private Sub Command1_Click()Dim Link As New ADODB.ConnectionDim rs As New ADODB.RecordsetLink.CursorLocation = adUseClientLink.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=ACCESS\kehu.mdb;Persist Security Info=False"Link.Openrs.Open "Select * From kehu Where company_name like '%" & txtCompany.Text & "%'", Link, adOpenDynamic, adLockOptimisticIf rs.RecordCount > 0 Then '填写数据
MsgBox rs.Fields("beizhu").Value
Else MsgBox "没有这个记录!"
End IfEnd Sub========================
Private Sub Form_Load()Dim DTbase As StringDTbase = App.Path + "\access\kehu.mdb"Set objcn = New ConnectionWith objcn
.Provider = "Microsoft.Jet.OLEDB.4.0"
.CursorLocation = adUseClient
.Open DTbase
End With
'建立数据库联接
Set conn = New RecordsetWith conn Set .ActiveConnection = objcn
.CursorLocation = adUseClient
.CursorLocation = adUseClient
.LockType = adLockOptimistic
'获取客户备注信息End WithSet flexshow.DataSource = objscore
'设置列数
flexshow.Cols = 1
'列标题 flexshow.TextMatrix(0, 0) = "备注"
'设置列宽
flexshow.ColWidth(0) = 2000End Sub
解决方案 »
- MDI窗体的最大化问题和禁用快捷键的问题??
- 挑战VB高难度(满分)
- 如何在数据库里读取表名?
- 尋VB原代碼。學習之用,小型進銷存系統即可
- 请写一个dbado处理事务的例子。在线等待,100分。不够再加。
- 请教:如何在ADO控件中提交SQL指令?
- 安装SQL SERVER2000时出现的问题,急!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
- 比较烦的问题,有什么办法可以开机就运行我的命令行呀???
- 支持蒙文输入的文本框
- 简单的问题,各位请进。分不是问题!!!
- 正解 VB.NET日期/时间类型值加减运算
- method or data member not found ?why
Dim WithEvents adoPrimaryRS As RecordsetPublic Sub OpenData(ByVal str1 As String)
Dim i As Integer
Dim db As Connection
On Error GoTo errOut
Set db = New Connection
db.CursorLocation = adUseClient
db.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + DATA_PATH + ";Persist Security Info=Fals"
Set adoPrimaryRS = New Recordset
adoPrimaryRS.Open str1, db, adOpenStatic, adLockOptimistic
Set DataGrid1.DataSource = adoPrimaryRS
mbDataChanged = False
If adoPrimaryRS.EOF = False Then adoPrimaryRS.MoveLast
If adoPrimaryRS.BOF = False Then adoPrimaryRS.MoveFirst
If DataGrid1.Visible = False Then DataGrid1.Visible = True
DataGrid1.Refresh
DataGrid1.AllowAddNew = True
Rstrict
errOut:
End Sub