运行程序时出现此错误。 System.nullreferenceexception: object reference not set to an instance of an object
。看来错误指向查询数据库的部分。这是代码
cmdx.Connection = cnn
cmdx.CommandText = "SELECT farmer_centre from farmer WHERE farmer_num ='" & fnumDField.Text.Trim & "'"
myDatad = cmdx.ExecuteReader
While myDatad.Read()
Dim dbCentre As String = myDatad(0).ToString
End While
我将dbCentre全局声明为
Dim dbCentre As String
。
我该怎么办?我使用的是vb而数据库是访问