SQL數據類型不匹配運行時表達低於我得到一個錯誤說:標準表達式
Data type mismatch in criteria expression
的消息框是用來識別發生錯誤,它會檢查點1,那麼它停止!
Dim table2 As New DataTable
Dim recordcount2 As Integer
Dim command2 As String = "SELECT * FROM [Results] where " & "[TestID] = " & " '" & CInt(LocationID) & "'"
Dim adapter2 As New OleDb.OleDbDataAdapter(command2, conn)
table2.Clear()
MsgBox("Checkpoint 1")
recordcount2 = adapter2.Fill(table2)
MsgBox("Checkpoint 2")
的代碼是在我的方案本節:按鈕
Try
'Defining variables
Dim table As New DataTable
Dim command As String
Dim recordCount As Integer
Dim LocationID As Integer
command = "SELECT * FROM [Test] where " & "[MachineID] = " & " '" & machineID & "'" 'SQL command to find if there is a usename stored with that is in username text box
Dim adapter As New OleDb.OleDbDataAdapter(command, conn) 'adapter
table.Clear() 'adding data to a table.
recordCount = adapter.Fill(table)
If recordCount <> 0 Then
For i = 0 To recordCount
Try
LocationID = CInt(table.Rows(i)(0))
Dim table2 As New DataTable
Dim recordcount2 As Integer
Dim command2 As String = "SELECT * FROM [Results] where " & "[TestID] = " & " '" & CInt(LocationID) & "'"
Dim adapter2 As New OleDb.OleDbDataAdapter(command2, conn)
table2.Clear()
MsgBox("Checkpoint 1")
recordcount2 = adapter2.Fill(table2)
MsgBox("Checkpoint 2")
If recordcount2 <> 0 Then
For x = 0 To recordcount2
MsgBox("yay1")
Dim TestID As String = table2.Rows(x)(1)
Dim Thickness As String = table2.Rows(x)(2)
Dim TargetFilter As String = table2.Rows(x)(9)
Dim SNR As String = table2.Rows(x)(3)
Dim STD As String = table2.Rows(x)(4)
MsgBox("yay2")
Dim M1 As String = table2.Rows(x)(5)
Dim M2 As String = table2.Rows(x)(6)
Dim kVp As String = table2.Rows(x)(7)
Dim mAs As String = table2.Rows(x)(8)
MsgBox("yay3")
Dim CNR As Short = (CLng(M1) - CLng(M2))/2
MsgBox("Further")
dgvViewData.Rows.Add(TestID, Thickness, CStr(SNR), CStr(STD), CStr(M1), CStr(M2), kVp, mAs, CStr(CNR))
Next
Else
MsgBox("RIP")
End If
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
Next
Else
MsgBox("There data for this machine.")
End If
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
代碼
Try
Dim table As New DataTable
Dim command As String
Dim recordCount As Integer
Dim TestNum As String = "1"
command = "SELECT * FROM [Results] where " & "[TestID] = " & " '" & CStr(TestNum) & "'"
Dim adapter As New OleDb.OleDbDataAdapter(command, conn)
table.Clear()
recordCount = adapter.Fill(table)
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
感謝您的快速性反應,我改變了命令2本: Dim command2 As String =「SELECT * FROM [Results] where」&「[TestID] =」&「'」&CStr(LocationID)&「'」 但是我仍然收到相同的錯誤! 另外在訪問時,TestID是一個數字:https://gyazo.com/5965941b5d3a56678971e42dd5de84a0 –
你確定錯誤是本地的那行代碼?嘗試擺脫一切不需要的東西,然後再次運行,以確保錯誤不是來自腳本中其他地方的錯誤。另外,我注意到你的參數化[TestID]。沒有理由,因爲你很難編碼它。 – 2016-04-15 02:01:45
基本上什麼我的代碼是幹什麼的,用戶給予了機號,我希望所有的那臺機器已經做在DataGridView列出的結果,這裏是aphoto數據庫關係https://gyazo.com/11d9d441031fc76a8f0338d6f8339eff –