0
我不確定爲什麼這段代碼不起作用 我跟着根據表字段的數據,它仍然無法使SQL Datareader工作。我已經檢查過表格和所有數據區域,一切都是正確的。但我仍然無法從數據庫中讀取數據。幫助T.Tasp.net.vb當沒有數據存在時無效嘗試讀取
Dim connectionString = ConfigurationManager.ConnectionStrings("CleanOneConnectionString").ConnectionString
Dim myConn As New SqlConnection(connectionString)
myConn.Open()
Dim cmd = "Select * from [Member] where Email = @Email"
Dim myCmd As New SqlCommand(cmd, myConn)
myCmd.Parameters.AddWithValue("@Email", emailBox.Text)
Dim objReader As SqlDataReader
objReader = myCmd.ExecuteReader()
objReader.Read()
Result.Text = " " 'initialise label to show correct message for available or found
'Check the reader see if any record found matching WHERE
If (objReader.Read()) Then
'read=true, check Password
'Dim tpassword As String = objReader.GetString(5)
'If tpassword = passwordBox.Text Then
'Result.Text = "** Login Succcessful **"
Result.Text = objReader.GetString(1)
'Else
'Result.Text = "Invalid Password" & objReader.GetString(5) & passwordBox.Text
'End If
'reader=false, no such records matching WHERE
Else
Result.Text = objReader.GetString(1)
End If
myCmd.Dispose()
myConn.Dispose()
當您運行原始SQL(使用SQL分析器查看)時,是否從數據庫中獲取任何行?它是否進入循環? – gbn
請注意這一點,不,但我確信我可以通過SQLDataReader獲取行,因爲這一個,我似乎無法檢索任何行。我已經嘗試了無數次 –