Join 306,813 VB.NET Programmers for FREE! Get instant access to thousands of VB.NET experts, tutorials, code snippets, and more! There are 1,686 people online right now. Registration is fast and FREE... Join Now!
hi, i have a combobox which when selected it has to populate other text boxes from the ms access database. but instead of it populating it gives the error mesage:An unhandled exception of type 'System.Data.OleDb.OleDbException' occurred in system.data.dll on line : Dim objReader As OleDbDataReader = cmd.ExecuteReaderplease assist!
CODE
Private Sub devstaffid_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles devstaffid.SelectedIndexChanged strSQL = "SELECT * FROM employees WHERE Persal_Number = " & devstaffid.Text & " " oledbcon.Open() Dim cmd As New OleDbCommand(strSQL, oledbcon)
Dim objReader As OleDbDataReader = cmd.ExecuteReader objReader.Read() TextBox2.Text = objReader("Component_Description") TextBox1.Text = objReader("Surname" & "Initials") objReader.Close() oledbcon.Close()
strSQL = "SELECT * FROM employees WHERE Persal_Number = " & devstaffid.Text & " "
try doing this
CODE
strSQL = "SELECT * FROM employees WHERE Persal_Number = " & cint(devstaffid.Text) & " "
Thats the first bug i saw. when concatenating query statements, you will need to explicitely change the variable location to the data type of the field.
strSQL = "SELECT * FROM employees WHERE Persal_Number = " & devstaffid.Text & " "
try doing this
CODE
strSQL = "SELECT * FROM employees WHERE Persal_Number = " & cint(devstaffid.Text) & " "
Thats the first bug i saw. when concatenating query statements, you will need to explicitely change the variable location to the data type of the field.
type your code in SelectionChangeCommitted event of combo box
CODE
Private Sub ComboBox1_SelectionChangeCommitted(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectionChangeCommitted #your code here End Sub
type your code in SelectionChangeCommitted event of combo box
CODE
Private Sub ComboBox1_SelectionChangeCommitted(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectionChangeCommitted #your code here End Sub
hi, the code is still giving the same error message after the above changes.
QUOTE(sonia.sardana @ 6 Jun, 2009 - 09:18 AM)
Ur probs is solved or not?If not,so dat i can answer it?Reply!
no, sorry but my problem is not solved i still get the same error message.
Dim con As OleDbConnection Dim da As OleDbDataAdapter Dim dt As DataTable Dim strQuery As String Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load strQuery = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\b1.mdb;Persist Security Info=True" con = New OleDbConnection(strQuery) con.Open() Me.Text = con.State.ToString strQuery = "Select * from Table1" da = New OleDbDataAdapter(strQuery, con) dt = New DataTable da.Fill(dt) With ComboBox1 .DataSource = dt .DisplayMember = "Name" .ValueMember = "ID" End With End Sub
Private Sub ComboBox1_SelectionChangeCommitted(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectionChangeCommitted strQuery = "Select * from Table1 Where ID=" & ComboBox1.SelectedValue da = New OleDbDataAdapter(strQuery, con) dt = New DataTable da.Fill(dt) TextBox1.Text = dt(0)(0) TextBox2.Text = dt(0)(1) End Sub
Dim con As OleDbConnection Dim da As OleDbDataAdapter Dim dt As DataTable Dim strQuery As String Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load strQuery = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\b1.mdb;Persist Security Info=True" con = New OleDbConnection(strQuery) con.Open() Me.Text = con.State.ToString strQuery = "Select * from Table1" da = New OleDbDataAdapter(strQuery, con) dt = New DataTable da.Fill(dt) With ComboBox1 .DataSource = dt .DisplayMember = "Name" .ValueMember = "ID" End With End Sub
Private Sub ComboBox1_SelectionChangeCommitted(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectionChangeCommitted strQuery = "Select * from Table1 Where ID=" & ComboBox1.SelectedValue da = New OleDbDataAdapter(strQuery, con) dt = New DataTable da.Fill(dt) TextBox1.Text = dt(0)(0) TextBox2.Text = dt(0)(1) End Sub
hi, i took ur code and put it into my system and changed fields to suit mine, but before i run it, its complaining about dt saying "class 'system.data.datatable' cannot be indexed because it has no default property"
Dim con As OleDbConnection Dim da As OleDbDataAdapter Dim dt As DataTable Dim strQuery As String Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load strQuery = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\b1.mdb;Persist Security Info=True" con = New OleDbConnection(strQuery) con.Open() Me.Text = con.State.ToString strQuery = "Select * from Table1" da = New OleDbDataAdapter(strQuery, con) dt = New DataTable da.Fill(dt) With ComboBox1 .DataSource = dt .DisplayMember = "Name" .ValueMember = "ID" End With con.close() <==== Add this End Sub
Private Sub ComboBox1_SelectionChangeCommitted(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectionChangeCommitted conn.open() <==== Add this strQuery = "Select * from Table1 Where ID=" & ComboBox1.SelectedValue da = New OleDbDataAdapter(strQuery, con) dt = New DataTable da.Fill(dt) TextBox1.Text = dt(0)(0) TextBox2.Text = dt(0)(1) conn.close() <===== Add this End Sub
This post has been edited by woodjom: 23 Jun, 2009 - 07:43 PM