binding testbox dataset

srs2000

Member
Joined
Sep 1, 2005
Messages
5
Programming Experience
Beginner
I have a textbox bound to a dataset field, should this text box automatically update with the data in that field? Yes/No?

The book im working from basically has a drop down box that I select a country from, this then fills the dataset with customers from that country, and in the book the application then shows the first customers name from that country in the textbox(based on the book having the textbox bound to dataset->customer field, will auto update the textbox.text value with the data from the dataset)

However when i recreate the example from the book the textbox field just stays empty upon selecting a country from the dropdown box.

I know the dataset is ok as i can manually say textbox1.text = ds.etc etc

Any advice would be much apprciate.

my code for the drop down box change is as follows

Private Sub cboCountry_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboCountry.SelectedIndexChanged
DsCustomers1.Clear()
Dim con As New Component1
con.DsCustomers1 = con.FillCustomers(cboCountry.Text)
positionindicator()
MsgBox(con.DsCustomers1.Tables.Item("customers").Rows(1).Item(1).ToString) 'just a line te test dscustomers1 is filling
End Sub

code for fillcustomers as follows

Public Function FillCustomers(ByVal country As String) As LearningVBdata.dsCustomers
Dim ds As New LearningVBdata.dsCustomers
Me.OleDbConnection1.Open()
Me.OleDbDataAdapter2.SelectCommand.Parameters.Item(0).Value = country
Me.OleDbDataAdapter2.Fill(ds)
Me.OleDbConnection1.Close()
Return ds
End Function
 
I assume your customer Details and Country are within the same table??

If so then you do not need cboCountry_SelectedIndexChange - it will do it automatically.
Also don't clear the dataset, or call the fillCustomers, as every time you select a customer in your list, you are calling back and loading data from your database - you only need to fill the dataset once and close the connection.

I use something similar to display address information for customers in my customer table, the user selects a customer in the list, and some labels then display the address info. In fact it's set out almost exactly the same as what you are asking.

I use the following code;

VB.NET:
Private Sub Form1_Load (.....)
 
try
conCustomer.open()
me.daCustomer.fill(dsCustomers1)
catch ex as exception
messagebox.show(ex.message)
finally
conCustomer.close()
end try
 
End Sub

Hope that helps you along the way.

Regards,
Luke
 
Back
Top