Connecting Tech Pros Worldwide Forums | Help | Site Map

strongly typed dataset to textbox

Member
 
Join Date: Oct 2006
Location: Netherlands
Posts: 92
#1: Sep 25 '09
Hello,
I am moving from vb.net to c#.
Now i am busy with the strongly typed datasets and i want to have a value from the dataset into a textbox.
Now, i have the dataset (dataset1.xsd) where i created a tableadapter (credentials).
How can i get the value of a record to an textbox or label, or what so ever?

I use these syntaxis:
DataSet1TableAdapters.CredentialsTableAdapter DSCredentials = new DataSet1TableAdapters.CredentialsTableAdapter();
DataSet1.CredentialsDataTable Table;

Cheers!
Paul

Familiar Sight
 
Join Date: Jul 2009
Location: Calgary, Alberta, Canada
Posts: 233
#2: Sep 25 '09

re: strongly typed dataset to textbox


There's two ways to do this that I know of.

The first way is to bind your textbox or label to the appropriate field in the database. This MSDN page should have some helpful information for you. Personally though, I'm not a fan of this solution. I've had problems with databindings in the past, where they don't behave exactly how I want. This is a personal opinion though, you may find you like the DataBindings solution as it is much simpler.

The alternative is to manage the database yourself. For example, if you've got a DataTable in your DataSet, you should be able to pull your data out of it and populate your text boxes and labels. Then when you want to update your DataSet, do the opposite and write the data from the textboxes back in.

Does that give you any ideas?
Member
 
Join Date: Oct 2006
Location: Netherlands
Posts: 92
#3: Oct 7 '09

re: strongly typed dataset to textbox


Hey GaryTexmo,
Sorry for the big delay.
The first one you described seems logic. I haven't thought about that :(.
Second one i have to try.
Usually i had an function that returned a tabel.
From there i created a new table and did it like this:
Expand|Select|Wrap|Line Numbers
  1. DataTable Table = new Datatable();
  2.  
  3. Table = SelectQuery( "SELECT * FROM Table1 ");
  4.  
  5. Textbox1.text = Table.Rows[0].Item("id");
Is that almost the same way or is it al lot different then?

Cheers, Paul
Reply