I have a program setup for which I would like to pull specific data from an Access database I have created. I know the connection to the database is functioning as I can pull mass data to populate a list box. Where I am having trouble is this. I would like to select a name from said list box and have the database return only information based on the name selected. Once I pull this information I would like to then place each item from this data into it's relevant place on the form. I'd rather not do this using a datagrid on the form. This is what I have currently.
*Note, the names being displayed in the list box is a direct match to the primary keys of each row
Expand|Select|Wrap|Line Numbers
- Private Sub OK_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK_Button.Click
- Dim selectedchar As String = characterlst.SelectedItem
- Dim dt As New DataTable
- con.ConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source = C:\Documents and Settings\Tech\My Documents\4e.mdb;"
- con.Open()
- sql = "SELECT * FROM details WHERE [Name]=" & selectedchar
- da = New OleDb.OleDbDataAdapter(sql, con)
- da.Fill(ds, "opening")
- Try
- Form1.Nametxt.Text = ds.Tables("opening").Rows(0).Item(0)
- Catch ex As Exception
- MessageBox.Show(ex.Message & " - " & ex.Source)
- End Try
- con.Close()
- Me.DialogResult = System.Windows.Forms.DialogResult.OK
- Me.Close()
- End Sub
"no value given for one or more required parameters vb access"
If I change the select statement to read
"SELECT * FROM details WHERE Primary Key =" & selectedchar
it throws me an error saying the syntax is incorrect
In both instances the error is thrown at line 8.
Any help would be much appreciated.