在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 ...'嗎? –