在vb.net中执行数据读取器命令时,我正面临错误。它抛出处理。这个字段就像你在文本框中输入员工ID一样,然后它将在数据库中捕获其他字段名称,部门。在vb.net中为数据读取器获取错误
这里是我的代码
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
Dim conn As New MySql.Data.MySqlClient.MySqlConnection
Dim strConnectionString As String =ConfigurationManager.ConnectionStrings("testConnectionString").ConnectionString
Dim sqlQuery As String = "SELECT * hr_record WHERE Emplid='" & txt1.Text & "'"
Using sqlConn As New MySqlConnection(strConnectionString)
Using sqlComm As New MySqlCommand()
With sqlComm
.CommandText = sqlQuery
End With
Try
sqlConn.Open()
Dim sqlReader As MySqlDataReader = sqlComm.ExecuteReader()
While sqlReader.Read()
txt1.Text = sqlReader("Emplid").ToString()
TextBox1.Text = sqlReader("Nama").ToString()
TextBox2.Text = sqlReader("DeptDesc").ToString()
End While
Catch ex As MySqlException
MessageBox.Show(ex.Message)
End Try
End Using
End Using
End Sub
你会得到什么错误? – Arion
@Arion我收到错误“连接必须有效并打开。” 'Dim sqlReader As MySqlDataReader = sqlComm.ExecuteReader()' – kolapopo
你的查询不应该是'SELECT * FROM hr_record ...'吗? –