So, what i am trying to do is, if i select values from the first two combo box and click search it should display the result in third text box. I am using Ms Access as my database.
coding in VB to link to DB
Imports System.Data.OleDb
Public Class Form1
Dim v_HardnessDbconn As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;DataSource=C:\Users\Desktop\Hardness.accdb")
Dim v_datareader As OleDbDataReader
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
v_HardnessDbconn.Open()
v_HardnessDbconn.Close()
End Sub
coding on the search box
Private Sub searchtext_Click(sender As Object, e As EventArgs) Handles searchtext.Click
v_HardnessDbconn.Open()
TextBox1.Clear()
Dim Str As String
Str = "SELECT * From Items Where (Material = '" & ComboBox1.Text & "', Hardness = '" & ComboBox2.Text & "')"
Dim v_dbCommand As OleDbCommand
v_dbCommand = New OleDbCommand(Str, v_HardnessDbconn)
Dim v_dataReader As OleDbDataReader = v_dbCommand.ExecuteReader()
If v_dataReader.HasRows Then
While v_dataReader.Read
TextBox1.Text = v_dataReader("Material Code").ToString
End While
v_HardnessDbconn.Close()
End If
End Sub
End Class
error getting after running it
An unhandled exception of type 'System.Data.OleDb.OleDbException' occurred in System.Data.dll
Additional information: Syntax error (comma) in query expression '(Material = 'Plain Carbon Steel ( AISI 1010- AISI 1030)', Hardness = '150-180')'.
Can someone please help.
Is there some mistake i made in this expression, where i am choosing values from two different combo boxes and then reading those values in the database to display my result :
Str = "SELECT * From Items Where (Material = '" & ComboBox1.Text & "', Hardness = '" & ComboBox2.Text & "')"
or is something wrong with my database?