Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
C# Typed DataSet Questions
Message
From
14/04/2008 12:49:04
Timothy Bryan
Sharpline Consultants
Conroe, Texas, United States
 
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Miscellaneous
Thread ID:
01310405
Message ID:
01310439
Views:
18
Hi Kevin,

>Ok, here's my next set of newby questions. I am learning but questions still abound.....
>
>I have come up with this code from what other people have posted. In this example, DSCustomer is a typed dataset. I am
>still in a state of foggyness because all I have is bits and pieces.
>
>
>string sSelectCommand = "select * from Customers where CustomerKey = 1";
>
>SqlDataAdapter oDataAdapter = new SqlDataAdapter(sSelectCommand, oConnection);
>DSCustomer oDataSet = new DSCustomer();
>oDataAdapter.Fill(oDataSet, "DSCustomer");
>
>// Add a row
>oDataSet.Tables[0].Rows.Add();
>
>
>
>
>1) What's the syntax for changing the value of a data item in the row?
How about this:
// If you want to change the data manually in code
// Initialize your dataset and fill it.
// Get the table out.
DataTable dtCustomers = DataSet.Tables[0];
// or
DataTable dtCustomers = DataSet.Tables["Customers"];
// Create a new row
DataRow newRow = dtCustomers.NewRow();
// Edit the column values
newRow["FirstName"] = "John";
newRow["LastName"] = "Jones";
// Add the row back to the table
after setting all the columns
dtCustomer.Rows.Add(newRow);
// Call accept changes on the DataSet
dsCustomers.AcceptChanges();
>
>2) How do I save the changes to the back end?

See above
>
>3) Could someone point me to examples of binding the DS to form controls?

There are lots of ways to do this. Here is one:
lstCustomers.DataSource = dsCustomers;
lstCustomers.DisplayMember = "Customers.CustomerName";

Or just set the properties in the property sheet and initialize the dataset in the load event with a call to to fill the DataSet.

Kevin, in the VS help index type in DataSet.AcceptChanges and you will find a good example of the above.

Tim
Timothy Bryan
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform