In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces how to use the SQL command in C#, which has a certain reference value. Interested friends can refer to it. I hope you will gain a lot after reading this article. Let's take a look at it.
The C # language has a lot to learn. Here we mainly introduce the C # SQL command, including the DELETE command indicating the records to be deleted.
The process of inserting, modifying, and deleting can be easily realized by SQL statements. The following code executes a C # SQL command to insert a record.
/ / SQL command String sSQLCommand = "INSERT INTO Person (Age, FirstName, Description, Updated)" + "VALUES (55, 'Bob',' Is a Penguin', '2001-12-25 20 30 command 15'); / / create command object ADOCommand cmdAdder = new ADOCommand (sSQLCommand, DB_CONN_STRING); cmdAdder.ActiveConnection.Open (); / / Execute the SQL command int nNoAdded = cmdAdder.ExecuteNonQuery () System.Console.WriteLine ("Row (s) Added =" + nNoAdded + "")
Note: the try/catch code does not appear in the above example, but should include the above code.
insert
The above code inserts a record by creating a C # SQL command and executing it. Some considerations when writing a C # SQL command are as follows:
1. Numerical data should be expressed directly. There are no single quotes (').
two。 The representation of the string should be enclosed in single quotation marks ('blah').
3. Make sure that the string does not contain any embedded single (double) quotation marks. This will confuse things.
4. Date and time data are represented in an internationally accepted form wrapped in single quotation marks ('YYYY/MM/DD HH:MM:SS').
Modify
The UPDATE command indicates the data to be modified and the action to be modified. The return value of ExecuteNonQuery () indicates the number of records changed, so the following code returns 5. 5 if there are five Peter's in the form.
String sSQLCommand = "UPDATE Person SET Age = 27 WHERE FirstName = 'Peter'"
Delete
The DELETE command indicates the record to be deleted. The return value of ExecuteNonQuery () indicates the number of records changed, so the following code returns 2. 0 if there are 2 Bobo in the form. Both Bobo will be deleted.
String sSQLCommand = "DELETE FROM Person WHERE FirstName = 'Bobo'"; Thank you for reading this article carefully. I hope the article "how to use SQL commands in C#" shared by the editor will be helpful to everyone. At the same time, I also hope you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.