How to...?

  • Thread starter Thread starter ElHombre
  • Start date Start date
E

ElHombre

Hi!

I'm new to C#.

In a SQL-database I have:

tblZipCodes:
ZipCodeID
ZipCode
City

tblCompanyInfo:
CompanyID
CompanyName
Adress
ZipCodeID
Phone

Now on the form, in C#, I'll have an extra textbox - 'city' - which
will display what city after
the ZipCodeID, which is a combobox, has been updated.

I've been working with msaccess 2000 for some years. I'm new to C#, but
it is interesting.

How do I fill the combobox on the form with data from the tblZipCodes,
so that it is synchronized
with data chosen in the other textboxes?

Do I create a new dataAdapter or...?

I would be more than happy if someone could guide me on this subject
:-)

??????????????????????????????????????????????????????????

Me.Name
 
When the form loads, one way is that you can use a datareader with a
standard sql query and walk through the reader, adding each item to the
combobox. This will fill the combobox for you.

Now, you can keep it synced by creating a BindingManagerBase object, setting
its context to the DataSet/DataTable that contains the ZipCode Column, and
adding something like this:

cbozipcode.DataBindings.Add("Text", Ds1, "Employees.Zip_Code")

This will bind the Employees table's Zip_Code column value for any given
row, to the "Text" property of cbozipcode.

Instead of a datareader, you can also just fill another datatable, and
relate it back to the main table - the datarelation can be bound so that it
automatically filters to the right record. Either way will work.

If you do this, add the dataRelation between the
tables.http://www.knowdotnet.com/articles/datarelation.html

and then bind via
comboBox.DataSource = DataSetObjectName 'ie. ds1
comboBox.DataMember = "DataSetFriendlyName.TableName" ' ie "Employees.Leave"

Lemme know if you have any problems.
 
Back
Top