My recent project has something to do with the database-share the analysis materials here-by the way, I am a computer repair engineer.
// -- The idea is to use a sqldataadapter to first retrieve data to the able, modify the data in the datatable to be updated, mainly by setting
Empadapter. updatebatchsize = 100; // -- the default value of this attribute indicates that the record is processed for the next time. Do not set it to too large.
Commandupdater. updatedrowsource = updaterowsource. None;
// ----------- Improve performance
Using system;
Using system. Data;
Using system. configuration;
Using system. collections;
Using system. Web;
Using system. Web. Security;
Using system. Web. UI;
Using system. Web. UI. webcontrols;
Using system. Web. UI. webcontrols. webparts;
Using system. Web. UI. htmlcontrols;
Using system. Data. sqlclient;
Public partial class default3: system. Web. UI. Page
{
Protected void page_load (Object sender, eventargs E)
{
// Data container
Datatable btmm = new datatable ();
Sqldataadapter empadapter = new sqldataadapter ();
// ----------- Select data
Sqlconnection dbconselect = new sqlconnection ();
// ------------- Copy data to this connection
Sqlconnection dbconupdater = new sqlconnection ();
Sqlcommand commandselect = new sqlcommand ();
Sqlcommand commandupdater = new sqlcommand ();
// Donet
Dbconselect. connectionstring = system. configuration. configurationmanager. connectionstrings ["connectionstring"]. connectionstring;
// Donet
Dbconupdater. connectionstring = system. configuration. configurationmanager. connectionstrings ["connectionstring"]. connectionstring;
// --------- Select the updated data
Commandselect. commandtext = "select * from B ";
Commandselect. commandtype = commandtype. text;
Commandselect. Connection = dbconselect;
// --------------------------------------- Set Update
Commandupdater. commandtext = "Update B set id = @ ID ";
Commandupdater. Connection = dbconupdater;
// -- Add Parameters
Sqlparameter A = new sqlparameter ("@ ID", sqldbtype. varchar, 50, "ID"); // note that the last address represents the Column Retrieved From the data source
Commandupdater. Parameters. Add ();
Empadapter. selectcommand = commandselect;
Empadapter. updatecommand = commandupdater;
Empadapter. Fill (btmm); // --- Call commandselect to retrieve data
Dbconselect. Close ();
Foreach (datarow DR in btmm. Rows)
{
Dr ["ID"] = "--ooo" + system. datetime. Now. tostring ();
}
// Update trigger
Empadapter. rowupdated + = new sqlrowupdatedeventhandler (onrowupdated );
Label1.text = "";
Empadapter. updatebatchsize = 100; // -- the default value of this attribute indicates that the record is processed for the next time. Do not set it to too large.
Commandupdater. updatedrowsource = updaterowsource. None;
//--------------------------------------------------------
// Both maps the output parameter and the first returned row to the modified row in the dataset.
// Firstreturnedrecord maps the data in the first returned row to the changed row in dataset.
// None ignores any returned parameters or rows.
// Outputparameters maps output parameters to changed rows in dataset.
Try
{
Dbconupdater. open ();
Empadapter. Update (blog );
}
Catch (exception)
{
}
}
Private void onrowupdated (Object sender, sqlrowupdatedeventargs ARGs)
{
Label1.text + = args. rowcount. tostring () + "<br> ";
}
}
// ------------ Web. confing settings
<Connectionstrings>
<Add name = "connectionstring" connectionstring = "Data Source =.; initial catalog = g; user id = sa; Password = sa"/>
<Add name = "connectionstringinfo" connectionstring = "Data Source =.; initial catalog = g; user id = sa; Password = sa"/>
</Connectionstrings>