sp; // prepare command string string insertString = @" insert into Categories (CategoryName, Description) values (''''Miscellaneous'''', ''''Whatever doesn''''''''t fit elsewhere'''')"; // 1. Instantiate a new command with a query and connection SqlCommand cmd = new SqlCommand(insertString, conn); // 2. Call ExecuteNonQuery to send command cmd.ExecuteNonQuery(); } finally { // Close the connection if (conn != null) { conn.Close(); } } } ///<summary> /// use ExecuteNonQuery method for Update ///</summary> publicvoid UpdateData() { try { // Open the connection conn.Open(); // prepare command string string updateString = @" update Categories set CategoryName = ''''Other'''' where CategoryName = ''''Miscellaneous''''"; // 1. Instantiate a new command with command text only SqlCommand cmd = new SqlCommand(updateString);
// 2. Set the Connection property cmd.Connection = conn; // 3. Call ExecuteNonQuery to send command cmd.ExecuteNonQuery(); } finally { // Close the connection if (conn != null) { conn.Close(); } } } ///<summary> /// use ExecuteNonQuery method for Delete ///</summary> publicvoid DeleteData() { try { // Open the connection conn.Open();