怎样读取access数据库表中满足条件的记录

[复制链接]
查看11 | 回复2 | 2010-8-19 14:44:50 | 显示全部楼层 |阅读模式
Dim myArrayA(0) As String

Dim myArrayB(0) As String

Dim myArrayC(0) As String

Dim myArrayT(0) As String

Dim i As Integer

Dim myConnStr As String = "provider=Microsoft.Jet.OLEDB.4.0;" & " Data Source=D:\我的文档\student.mdb"

Dim myConn As OleDb.OleDbConnection = New OleDb.OleDbConnection(myConnStr)

myConn.Open()

Dim myCmd As OleDb.OleDbCommand = New OleDb.OleDbCommand()

myCmd.CommandType = CommandType.Text

myCmd.CommandText = "select A相电压Ua,B相电压Ub,C相电压Uc,时间 from 三相电压 where 序号=textbox1.text" '若是加上条件where 序号=textbox1.text 则会

'在运行时在Dim myReader As OleDb.OleDbDataReader = myCmd.ExecuteReader处报错“至少一个参数没有被指定值。”?

myCmd.Connection = myConn

Dim myReader As OleDb.OleDbDataReader = myCmd.ExecuteReader'创建DataReader对象

Do While myReader.Read()
'将数据库表中的元素读出到数组中

myArrayA(i) = myReader.Item("A相电压Ua")

ReDim Preserve myArrayA(UBound(myArrayA) + 1)

myArrayB(i) = myReader.Item("B相电压Ub")

ReDim Preserve myArrayB(UBound(myArrayB) + 1)

myArrayC(i) = myReader.Item("C相电压Uc")

ReDim Preserve myArrayC(UBound(myArrayC) + 1)

myArrayT(i) = myReader.Item("时间")

ReDim Preserve myArrayT(UBound(myArrayT) + 1)

i += 1

Loop

myConn.Close()
我想要将数据库表中的数据读到上面的数组中,但是必须满足条件where 序号=textbox1.text,textbox1中存有1,2.。。这样的整数,会报错,去掉条件读出的是所有记录,不满足要求,怎么办?请教各位,谢谢!

回复

使用道具 举报

千问 | 2010-8-19 14:44:50 | 显示全部楼层
myCmd.CommandText = "select A相电压Ua,B相电压Ub,C相电压Uc,时间 from 三相电压 where 序号=textbox1.text" 改为:myCmd.CommandText = "select A相电压Ua,B相电压Ub,C相电压Uc,时间 from 三相电压 where 序号='" + textbox1.text + "'"
回复

使用道具 举报

千问 | 2010-8-19 14:44:50 | 显示全部楼层
rec.open "select [a].name,.age,[c].height from a,b,c where a.no = b.no and b.no = c.no and a.no =8" 从abc8表中分别取出8条记录8个字段,每条记录的no字段都是8
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行