C # WinForm Form design-perform additions and deletions to the database

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.