这是我的程序,不过运行后,点击[button6]按钮,总是提示"在没有任何数据时进行无效的读取尝试".希望有高手能指点迷津,谢谢
PS:插入数据是可以的,但是读取就不行了.
Private Const linkstring As String = "Password=123;Persist Security Info=True;User ID=sa;Initial Catalog=mysql;Data Source=C506"
Dim link As New System.Data.SqlClient.SqlConnection(linkstring)
'上面的是先做一下准备工作,定义一些变量
Private Sub Button6_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
'点击按钮的程序
Dim sqlcode As String
sqlcode = "select 电压 from table1"
Dim execute As New System.Data.SqlClient.SqlCommand(sqlcode, link)
Dim myReader As System.Data.SqlClient.SqlDataReader = execute.ExecuteReader()
If link.State = ConnectionState.Open Then
Try
Dim a As String = myReader.GetValue(1)
'上面的getvalue(1)我先后换过getvalue(0),getstring(0),getstring(1),都不行
Catch e6x As Exception
MsgBox(e6x.Message)'取sql错误提示,那个[在没有任何数据时进行无效的读取尝试]就是打这儿来的
End Try
Else
MsgBox("ERROR")
End If
myReader.Close()
End Sub