--Indeed available databases (Anti-write, transaction, dataset constraints)

Source: Internet
Author: User
-I am so lazy today when I work overtime. I am brewing a new project. I have not figured out the name, and the main functions are kept confidential. The progress is 30%. I have done a good job of releasing the original code, don't a brother in the circle simulate dos?
// -- Decompress sqlcommandbuilder sqlcommandbuilder1 = new sqlcommandbuilder (sqldataadapter1 );
// Initialize the sqlcommandbuilder instance with the sqldataadapter1 Parameter
Dsdataset1.tables ["MERs"]. Rows [0]. Delete ();
// Delete the first row of data in the customers table in Dataset
Sqldataadapter1.update (dsdataset1, "MERs ");
// Call the update method to update the data in dataset from the database
Dsdataset1.tables ["MERs"]. acceptchanges ();

// -- Thing

Sqlconnection myconnection = new sqlconnection ("Server = (local); initial catalog = northwind; uid = sa; Pwd = 111 ;");
Myconnection. open ();
// Start a transaction
Sqltransaction mytrans = myconnection. begintransaction ();


// Create a command for the transaction
Sqlcommand mycommand = new sqlcommand ();
Mycommand. Connection = myconnection;
Mycommand. Transaction = mytrans;
Try
{
Mycommand. commandtext = "insert into region (regionid, regiondescription) values (110, 'description ')";
Mycommand. executenonquery ();
// Mytrans. Commit ();
Mycommand. commandtext = "insert into region (regionid, regiondescription) values (111, 'description ')";
Mycommand. executenonquery ();
// Submit. It is used to execute all execution statements together. If there is an error, throw it.
Mytrans. Commit ();
Response. Write ("successful write record! ");
}
Catch (exception ex)
{
// Roll back data
Mytrans. rollback ();
Response. Write (ex. tostring ());
Response. Write ("failed to write to database! ");
}
Finally
{
Myconnection. Close ();
}

}
}

// Create constraints
Sqlconnection mysqlcon = new sqlconnection ("Server =.; uid = sa; Pwd = sa; database = northwind ");
Sqldataadapter mydataadapter1 = new sqldataadapter ("select * from MERs", mysqlcon );
Sqldataadapter mydataadapter2 = new sqldataadapter ("select * from orders", mysqlcon );
Mysqlcon. open ();
Dataset dataset1 = new dataset ();
Mydataadapter1.fill (dataset1, "MERs ");
Mydataadapter2.fill (dataset1, "orders"); mainly creates a table with constraints ------------------ main CCB ------------ columns -----------------------------
Datarelation RR = dataset1. relations. Add ("MERs", dataset1.tables ["customers"]. Columns ["customerid"],
/** // External creation Constraint
Dataset1.tables ["orders"]. Columns ["mermerid"]);
Foreach (datarow prow in dataset1.tables ["MERs"]. Rows)
{// Create a cycle for a layman
Response. Write (prow ["mermerid"]);
Foreach (datarow crow in prow. getchildrows (RR ))
Internal build cycle
Response. Write (crow ["ordid"]);
}

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.