SQL and C # combine complete modifications to delete information

Source: Internet
Author: User

in--sql
--Create Ren's database and insert a messageCreate DatabaseRenGo Use RenGoCreate TableXinxi(Codenvarchar( -)Primary Key,--numberingNamenvarchar( -)--name)Insert intoXinxiValues('1001','Zhangsan')

In the previous operation, there is a bug, in the operation of "pruning", if the user lost the wrong number, no reminder, then you have to query whether there is this number of information before the operation

in//c#
//Modify for (; ; ) { //first query whether there is such a data, if any, to operate; if not, re-enter, know that the input is correct so far!! BOOLb =false;//using intermediate variablesConsole.Write ("Please enter the number you want to modify:"); stringNo =Console.ReadLine (); //Search ShowSqlConnection zhancnn =NewSqlConnection ("server=.; Database=ren;user=sa;pwd=123");//Connection//Statement of OperationSqlCommand Zhancmd =zhancnn. CreateCommand (); Zhancmd.commandtext="SELECT * from Xinxi where code= '"+ No +"'"; //statements that perform actionszhancnn. Open (); SqlDataReader SS=Zhancmd. ExecuteReader (); if(SS. HasRows)//whether there is data to be modified in the database{b=true; } zhancnn. Close (); if(b = =true)//If you have the data you want to modify{Console.WriteLine ("Find the ""+ No +""Information, are you sure you want to modify it? y/n"); if(Console.ReadLine (). ToUpper () = ="Y")//Determining Modifications{Console.Write ("Please enter the name you want to modify:"); stringMingzi =Console.ReadLine (); Zhancmd.commandtext="Update Xinxi set name= '"+ Mingzi +"' where code= '"+ No +"'";//since the above is instantiated, do not re-instantiate, note open and closezhancnn. Open (); Zhancmd. ExecuteNonQuery (); Zhancnn. Close (); Console.WriteLine ("number is"+ No +"the information modified successfully! "); } Else//Do not modify { } Break; } Else//If you don't have the data you want to modify{Console.WriteLine ("The database does not have this message, please enter the correct code!! "); }} console.readline ();

Modify and delete the same format, the execution statement is not the same! !

SQL and C # combine complete modifications to delete information

Related Article

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.