School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!
Welcome to Dream.In.Code
Become an Expert!

Join 340,155 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 3,992 people online right now. Registration is fast and FREE... Join Now!



selected index changed

Page 1 of 1

selected index changed populating textbox from selected index changed Rate Topic: -----

#1 melodimoeti  Icon User is offline

  • New D.I.C Head
  • Pip
  • Group: Members
  • Posts: 39
  • Joined: 20-April 09


Dream Kudos: 0

Posted 05 June 2009 - 03:50 AM

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!

 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()

	End Sub

Was This Post Helpful? 0
  • +
  • -


#2 woodjom  Icon User is offline

  • D.I.C Regular
  • Icon
  • View blog
  • Group: Members w/DIC++
  • Posts: 412
  • Joined: 08-May 08


Dream Kudos: 0

Posted 05 June 2009 - 04:44 AM

strSQL = "SELECT * FROM employees WHERE Persal_Number = " & devstaffid.Text & " "



try doing this
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.

Other than that, it all looks good.
Was This Post Helpful? 0
  • +
  • -

#3 melodimoeti  Icon User is offline

  • New D.I.C Head
  • Pip
  • Group: Members
  • Posts: 39
  • Joined: 20-April 09


Dream Kudos: 0

Posted 05 June 2009 - 06:25 AM

View Postwoodjom, on 5 Jun, 2009 - 01:44 PM, said:

strSQL = "SELECT * FROM employees WHERE Persal_Number = " & devstaffid.Text & " "



try doing this
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.

Other than that, it all looks good.

hi, it still gives the same error
Was This Post Helpful? 0
  • +
  • -

#4 noorahmad  Icon User is offline

  • Author
  • Icon
  • View blog
  • Group: Author w/DIC++
  • Posts: 2,198
  • Joined: 12-March 09


Dream Kudos: 1600

Posted 05 June 2009 - 09:32 PM

type your code in SelectionchangeCommitted event of combo box

   Private Sub ComboBox1_SelectionchangeCommitted(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectionchangeCommitted
#your code here
	End Sub

Was This Post Helpful? 0
  • +
  • -

#5 sonia.sardana  Icon User is offline

  • D.I.C Head
  • PipPip
  • Group: Members
  • Posts: 132
  • Joined: 01-June 08


Dream Kudos: 0

Posted 06 June 2009 - 12:18 AM

Ur probs is solved or not?If not,so dat i can answer it?Reply!
Was This Post Helpful? 0
  • +
  • -

#6 melodimoeti  Icon User is offline

  • New D.I.C Head
  • Pip
  • Group: Members
  • Posts: 39
  • Joined: 20-April 09


Dream Kudos: 0

Posted 06 June 2009 - 01:27 AM

View Postnoorahmad, on 6 Jun, 2009 - 06:32 AM, said:

type your code in SelectionchangeCommitted event of combo box

   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.

View Postsonia.sardana, on 6 Jun, 2009 - 09:18 AM, said:

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.
Was This Post Helpful? 0
  • +
  • -

#7 noorahmad  Icon User is offline

  • Author
  • Icon
  • View blog
  • Group: Author w/DIC++
  • Posts: 2,198
  • Joined: 12-March 09


Dream Kudos: 1600

Posted 06 June 2009 - 01:30 AM

change your query
strSQL = "SELECT * FROM employees WHERE Persal_Number = " & devstaffid.SelectedValue & " "

Was This Post Helpful? 0
  • +
  • -

#8 melodimoeti  Icon User is offline

  • New D.I.C Head
  • Pip
  • Group: Members
  • Posts: 39
  • Joined: 20-April 09


Dream Kudos: 0

Posted 06 June 2009 - 01:44 AM

View Postnoorahmad, on 6 Jun, 2009 - 10:30 AM, said:

change your query
strSQL = "SELECT * FROM employees WHERE Persal_Number = " & devstaffid.SelectedValue & " "

its changed but when i run it, it still gives error on objreader, error line =
 Dim objReader As OleDbDataReader = cmd.ExecuteReader

Was This Post Helpful? 0
  • +
  • -

#9 noorahmad  Icon User is offline

  • Author
  • Icon
  • View blog
  • Group: Author w/DIC++
  • Posts: 2,198
  • Joined: 12-March 09


Dream Kudos: 1600

Posted 06 June 2009 - 01:48 AM

ok here is my code
	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

Was This Post Helpful? 0
  • +
  • -

#10 melodimoeti  Icon User is offline

  • New D.I.C Head
  • Pip
  • Group: Members
  • Posts: 39
  • Joined: 20-April 09


Dream Kudos: 0

Posted 06 June 2009 - 02:28 AM

View Postnoorahmad, on 6 Jun, 2009 - 10:48 AM, said:

ok here is my code
	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"
Was This Post Helpful? 0
  • +
  • -

#11 noorahmad  Icon User is offline

  • Author
  • Icon
  • View blog
  • Group: Author w/DIC++
  • Posts: 2,198
  • Joined: 12-March 09


Dream Kudos: 1600

Posted 06 June 2009 - 02:45 AM

i attached the database and Vb.Net Project download it.

Attached File(s)


Was This Post Helpful? 0
  • +
  • -

#12 melodimoeti  Icon User is offline

  • New D.I.C Head
  • Pip
  • Group: Members
  • Posts: 39
  • Joined: 20-April 09


Dream Kudos: 0

Posted 06 June 2009 - 03:54 AM

View Postnoorahmad, on 6 Jun, 2009 - 11:45 AM, said:

i attached the database and Vb.Net Project download it.

thanks, but for some reason i can download the zip file...gives me an error mesage, can u maybe use winrar and resend.
Was This Post Helpful? 0
  • +
  • -

#13 melodimoeti  Icon User is offline

  • New D.I.C Head
  • Pip
  • Group: Members
  • Posts: 39
  • Joined: 20-April 09


Dream Kudos: 0

Posted 07 June 2009 - 10:36 AM

View Postmelodimoeti, on 6 Jun, 2009 - 12:54 PM, said:

View Postnoorahmad, on 6 Jun, 2009 - 11:45 AM, said:

i attached the database and Vb.Net Project download it.

thanks, but for some reason i can download the zip file...gives me an error mesage, can u maybe use winrar and resend.

thanks, its working
Was This Post Helpful? 0
  • +
  • -

#14 woodjom  Icon User is offline

  • D.I.C Regular
  • Icon
  • View blog
  • Group: Members w/DIC++
  • Posts: 412
  • Joined: 08-May 08


Dream Kudos: 0

Posted 23 June 2009 - 07:40 PM

	
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 June 2009 - 07:43 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1


Fast Reply

  

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users



Live Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month