标题:[求助]VB中如何在DATAGRID控件中显示ACCESS表格内容
取消只看楼主
monica
Rank: 1
等 级:新手上路
帖 子:24
专家分:0
注 册:2007-4-29
 问题点数:0 回复次数:1 
[求助]VB中如何在DATAGRID控件中显示ACCESS表格内容

向各位前辈请教一下:
我在ACCESS中创建了一个表kehu,里面就两个字段:company_name和beizhu
在VB中建了一个窗体frmEmpInfo2用来查询客户信息,我用的是模糊查询,想通过模糊查询company_name,把ACCESS中的beizhu信息返回到datagrid中,但是我的程序运行后就是不在datagrid中显示,而是另跳出一个提示框显示备注信息,请高手们指教一下。谢谢!
Option Explicit

Dim strsql As String

Dim rs As New ADODB.Recordset

Dim objscore As Recordset '保存客户信息

Dim conn As Recordset

Dim 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.Connection

Dim rs As New ADODB.Recordset

Link.CursorLocation = adUseClient

Link.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=ACCESS\kehu.mdb;Persist Security Info=False"

Link.Open

rs.Open "Select * From kehu Where company_name like '%" & txtCompany.Text & "%'", Link, adOpenDynamic, adLockOptimistic

If rs.RecordCount > 0 Then

'填写数据

MsgBox rs.Fields("beizhu").Value


Else

MsgBox "没有这个记录!"

End If

End Sub

========================
Private Sub Form_Load()

Dim DTbase As String

DTbase = App.Path + "\access\kehu.mdb"

Set objcn = New Connection

With objcn

.Provider = "Microsoft.Jet.OLEDB.4.0"

.CursorLocation = adUseClient

.Open DTbase

End With

'建立数据库联接
Set conn = New Recordset

With conn

Set .ActiveConnection = objcn

.CursorLocation = adUseClient

.CursorLocation = adUseClient

.LockType = adLockOptimistic

'获取客户备注信息

End With

Set flexshow.DataSource = objscore


'设置列数
flexshow.Cols = 1

'列标题

flexshow.TextMatrix(0, 0) = "备注"

'设置列宽

flexshow.ColWidth(0) = 2000

End Sub

搜索更多相关主题的帖子: DATAGRID 控件 ACCESS 表格 
2007-05-18 17:16
monica
Rank: 1
等 级:新手上路
帖 子:24
专家分:0
注 册:2007-4-29
得分:0 
不知道这个帖子有没有人回!

磨刀不误砍柴功!
2007-05-18 17:17



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-140489-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.302614 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved