JingFrequently usedRecordDon't look for troubleAnnoyingBytes(-_-There are already too many other
Compiled a database and a table. It can be compiled anyway ~
I will not discuss it here. The same person in the Tao is also clear.
For how to store dB links in the config file, refer to here
Http://www.cnblogs.com/Kenr/archive/2009/04/27/1444610.html
/// <Summary>
/// Sample generationCode(WriteAmoeba ~)
/// </Summary>
/// <Param name = "studentid">Student ID</Param>
/// <Param name = "studentname">Student name</Param>
Private VoidDbinsert (StringStudentid,StringStudentname)
{
SqlconnectionConnection =Null;
null ;
progress process, when insertion fails failed hour can return Roll
SqltransactionTransaction =Null;
Try
{
string . empty;
// tune config dB in the file chain connected string
Connection =New Sqlconnection(Configurationmanager. Deleetask ["DB. connectionstring"]);
Connection. open ();
Command = connection. createcommand ();
Transaction = connection. begintransaction ();
Command. Transaction = transaction;
Commtext + ="Insert into <dbname>. <schema>. <tablename>";
Commtext + ="(Student_id, student_name, last_update )";
Commtext + ="Select @ studentid, @ studentname, @ lastupdate";
Command. commandtext = commtext;
Command. Parameters. Add (New Sqlparameter("@ Studentid","<Field 1>"));
Command. Parameters. Add (New Sqlparameter("@ Studentname","<Field 2>"));
Command. Parameters. Add (New Sqlparameter("@ Lastupdate", System.Datetime. Now. tostring ()));
//Returns the number of inserted rows.
IntInsertcount = command. executenonquery ();
Transaction. Commit ();
}
Catch(ExceptionE)
{
//SendingRawErrorBackRoll
If(Transaction! =Null)
{
Transaction. rollback ();
}
//SetErrorThrowing to the previousLayer
ThrowE;
}
//Never forgetNote,DisconnectConnect
Finally
{
If(Connection! =Null)
{
Connection. Close ();
}
}
}