Access SQL select inner join statement
Posted on 2006-06-26
Could someone please help me! I am trying to select specific records from a table using sql and I get all the records all the time.
I am using two datatables Shifts and jobs, the join should be on JobNo and only select the ones that match the text selected in the listbox.
Here is the code.
Dim jobString As String
jobString = "'" & lstJobs.SelectedItem & "'" ' double, single, double quotes & [contents of textbox] & double,single,double quotes.
dbCommand.Connection = dbConnection 'defined at the top of the form
dbCommand.CommandType = CommandType.Text
dbCommand.CommandText = "Select * from shift inner join jobNo on shift.jobNo = jobs.jobNo where shift.JobNo = " & jobstring
da.SelectCommand = dbCommand
grdShift.Visible = True
grdShift.DataSource = dt
' the data grid shows all the records not just the ones that match the criteria