Provides a data service class that invokes GetDataSet to get the required dataset, then modifies it in the user interface, and finally calls Savedate to save the pending changes to the database.
Using System;
Using System.Data;
Using System.Data.SqlClient;
Namespace Asterdnet.databind
{
<summary>
Summary description for GetData.
</summary>
public class TestData
{
Private SqlDataAdapter da;
Public TestData ()
{
//
Todo:add constructor Logic here
//
}
Public DataSet GetDataSet ()
{
SqlParameter workparam=new SqlParameter ();
Da=new SqlDataAdapter ();
Build the Select Command
Da. SelectCommand =new SqlCommand ("SELECT * FROM Education", Conn);
Da. Fill (ds, "Education");
Build the Insert Command
Da. InsertCommand = new SqlCommand ("Insert into education (ID, education) VALUES (@ID, @Education)", conn);
Build the Delete command
Da. DeleteCommand =new SqlCommand ("Delete from education where id= @ID", conn);
Workparam=da. DELETECOMMAND.PARAMETERS.ADD ("@ID", SqlDbType.Int);
Workparam.sourcecolumn = "ID";
Workparam.sourceversion =datarowversion.original;
return DS;
}
Save the Change dataset
public void Savedate (DataSet dataset,string tablename)
{
Da. Update (Dataset,tablename);
}
}
}
In the example, I created a database of test, in which a education table was created, with two field IDs (int), education (char), passed in RC3.
The feeling is not vb6.0 with ado2.5 so convenient (just set the ActiveConnection, and then update on everything, now to write their own how to update the SqlCommand), but the programmer's ability to control a bit stronger.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.