Insert (ADD) database data ):
For example:
Sqlcommand cmd = new sqlcommand ("insert into person values (@ PID, @ pname, @ resolve X)", con );
Sqlparameter para = new sqlparameter ("@ PID", sqldbtype. varchar, 10); // describes the PID attribute
Para. value = P. PID; // PID value assignment
Cmd. Parameters. Add (para); // Add
Para = new sqlparameter ("@ pname", sqldbtype. varchar, 20 );
Para. value = P. pname;
Cmd. Parameters. Add (para );
Para = new sqlparameter ("@ psex", sqldbtype. varchar, 2 );
Para. value = P. Rows X;
Cmd. Parameters. Add (para );
Cmd. executenonquery (); // Execute
Update
Sqlcommand cmd = new sqlcommand ("Update person set pname = '" + P. pname + "', signature x ='" + P. limit x + "'where pid = '" + P. PID + "'", con );
Cmd. executenonquery ();
Delete
Sqlcommand cmd = new sqlcommand ("delete from person where pid = '" + PID + "'", con );
Cmd. executenonquery ();
Exception capture
Try
{
Normal execution successful
}
Catch (exception E)
{
Error
}