标题:如何用代码方式读取ACCESS中的数据?
只看楼主
xf_wolf
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2006-3-28
 问题点数:0 回复次数:1 
如何用代码方式读取ACCESS中的数据?

下面是我的代码,但好象没有效果,不知是怎么回事,请那位高手帮看一下,指点一二。
Dim ZDM As String
Try
'construct the command object and open a connection to the Contacts table

Dim cmdString As String = "Select ZDM from DZB WHERE ZMC = " & Grid1.Cell(j, 4).Text & " "
Dim connString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=hjsby.mdb"
Dim myConnection As OleDbConnection = New OleDbConnection(connString)

' Open connection
myConnection.Open()

'Create OleDbCommand object
Dim TheCommand As OleDbCommand = New OleDbCommand(cmdString, myConnection)

TheCommand.CommandType = CommandType.Text
' Create a DataReader and call Execute on the Command Object to construct it

Dim TheDataReader As OleDbDataReader = TheCommand.ExecuteReader()

While TheDataReader.Read()


ZDM = TheDataReader("ZDM").ToString()

End While
Catch ae As OleDbException
MsgBox(ae.Message())
End Try

搜索更多相关主题的帖子: ACCESS 数据 代码 
2006-03-28 00:32
tnt0318
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2006-3-28
得分:0 

其中连接字符串你可以对照下面修改
aastr = "Jet OLEDB:Database Password=;Data Source=D:\www\WebApplication1\database\test.mdb;Password=;Provider=Microsoft.Jet.OLEDB.4.0;Jet OLEDB:SFP=False;Extended Properties=;Jet OLEDB:Create System Database=False;"

2006-03-28 11:14



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




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

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