向各位前辈请教一下:
   我在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

解决方案 »

  1.   

    我用的是DataGrid 控件
    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
      

  2.   

    "MsgBox   rs.Fields( "beizhu ").Value "改一下  datagrid1.Columns(0).Value = rs.Fields( "beizhu ").Value