vb.net 求救啊,“未将对象引用设置到对象实例”

来源:百度知道 编辑:UC知道 时间:2024/05/04 10:43:11
Dim pbalance As Single
Dim tSum As Double = 0
Dim tConn As OleDbConnection = New OleDbConnection
Dim tComm As New OleDbCommand
Dim tReader As OleDbDataReader
tConn = New OleDbConnection(("PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE=" & Application.StartupPath + "\data.mdb"))
tComm.Connection = tConn
tComm.CommandText = "select p_balance from payments"
tConn.Open()
'tReader = tComm.ExecuteReader
While tReader.Read = True /程序在这里断了
pbalance = tReader.GetFloat(0)
tSum = tSum + pbalance
End While
tConn.Close()
Label19.Text = tSum
请大家帮帮忙~
While tReader.Read = True /程序在这里断了

这里改了下 While tReader.Read 还是同样的错

这位朋友
你改成:while tReader.Read()
就可以了
你试试,应该是对的,除非你程序本身有问题!
祝你早日解决问题!
朋友还在吗?怎么不回话!
问题解决了没有?

'tReader = tComm.ExecuteReader
这行注释掉了,没有执行。

While tReader.Read = True /程序在这里断了
这行中的“tReader”就是nothing了。

把上面的注释去掉就没事了。

imports system.data
imports system.data.oledb
.
.
Dim pbalance As Single
Dim tSum As Double = 0
Dim tConn As OleDbConnection = New OleDbConnection

Dim tComm As OleDbCommand

Dim tReader As OleDbDataReader
tConn = New OleDbConnection(("PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE=" & Application.StartupPath + "\data.mdb"))
tComm.Connection = tConn
tComm.CommandText = "select p_balance from payments"
tConn.Open()

tComm =new oledbcommand("select p_balance from payments",tConn)
tReader = tComm.ExecuteReader()

While tReader.Read = True /程序在这里断了
pbalanc