For the people who learn the database, the database is the most basic of additions and deletions (small series is actually just a small white =-=), this article, small series will explain the database and add and change operations
The main use when executing the database additions and deletions: command class ExecuteNonQuery execute commands with return value (int)
The following describes the steps to perform operations on a database:
(1) Create a connection (2) Creating commands (3) Set the connection and text of the command (SQL statement) (4) Open connection (5) Execute command (6) data returned using the command (7) Closing the Connection code demo:
1 strings ="server=.; database=sampledb;integrated security=true";2SqlConnection C =NewSqlConnection (s);3 C.open ();4SqlCommand Command =NewSqlCommand ();5 6 stringSql="Insert into Lesson (id,name) VALUES (' bzu001 ', ' Zhang San ')"7Command. Connection =C;8Command.commandtext =SQL;9 intn =command. ExecuteNonQuery ();TenMessageBox.Show ("added a"+n+"Data");
C # WinForm Form design-perform additions and deletions to the database