Access Data

lakshya

Member
Joined
Jul 28, 2006
Messages
9
Programming Experience
Beginner
Hi! Can anyone tell me how we can fill textboxes with columns from access database on selection of an primmary key item from the combobox. I have a form in which i have a combobox where i display the unique field of the table. I want when the user clicks on one item in combobox i can fill textboxes with the data related to that unique field(row).
 
Once you have your form set up, configured the DataAdapter/TableAdapter, and implemented a bit of databinding, it's just a matter of handling the combo's 'selected index changed' event. You can get the currently selected item and pass it to an SQL SELECT command then execute the query. Thats 'how' you would do it, which part in particular are you having trouble with?
 
send the syntax

I know it will be done with selectedindex change event of combo box but what exactly i have to write?
textbox1.text = ?
 
Send the syntax for what? If you can post the code we can better see what point you are up to, and then we'd be in a better position to advise on the next step.
 
hi

That problem is solved but whenever my form gets loaded the combobox from where i am selecting the id gets duplicated in it. It means if i have 5 id then i hide form and when i return it gets 10. Can u suggest wat to do?:eek:
 
How are you loading the values into the combobox, i'd suggest using databinding in this instance. Set the Datasource property of the combo to the datatable you are using and then set the displayMember property to the field name of the column you want it to display....

VB.NET:
ComboBox.DataSource = YouDatatable
ComboBox.DisplayMember = "your column name"
 
This is what i have done but still it duplicates. Have a look at Combobox code:
'
'ComboBox1
'
Me.ComboBox1.DataSource = Me.DataSet_Crs1
Me.ComboBox1.DisplayMember = "Course_MST.Course_ID"
Me.ComboBox1.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList
Me.ComboBox1.Location = New System.Drawing.Point(456, 232)
Me.ComboBox1.Name = "ComboBox1"
Me.ComboBox1.Size = New System.Drawing.Size(144, 24)
Me.ComboBox1.TabIndex = 1
Me.ComboBox1.ValueMember = "Course_MST.Course_ID"

I don't think its wrong coz its working for rest of the forms.
 
odd, if the combo os bound then the only data that should be displayed is that data that it is bound to. Are you doing anything else with the combobox elsewhere? Can you post all code relavent to the combobox?
 
combobox code

Ok i'm sending you all the code relevent to that combobox.

ComboBox1

Me.ComboBox1.DataSource = Me.DataSet_Crs1
Me.ComboBox1.DisplayMember = "Course_MST.Course_ID"
Me.ComboBox1.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList
Me.ComboBox1.Location = New System.Drawing.Point(456, 232)
Me.ComboBox1.Name = "ComboBox1"
Me.ComboBox1.Size = New System.Drawing.Size(144, 24)
Me.ComboBox1.TabIndex = 1
Me.ComboBox1.ValueMember = "Course_MST.Course_ID"

and also

Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
I =
CInt(ComboBox1.SelectedIndex)
Dim dsrw = DataSet_Crs1.Course_MST.Rows(I)
TextBox1.Text = dsrw("subject")
TextBox2.Text = dsrw("duration")
TextBox3.Text = dsrw("Fee(student)")
TextBox4.Text = dsrw("Fee(external)")
End Sub

I has been declared as integer in the class.

Now have a look and tell me what is going wrong?
 
Ok, i've had a look, but i can't see anything wrong with the way the combobox has been databound. Very odd, it could be bug in your program if it's working for all the other forms.
 
If you can post the project, leaving out the bin and debug folders then i can take a look when i get home. Apart from that it may be a matter of starting that form again.
 
Back
Top