Complete modification and deletion of ADO. NET and ado.net

Source: Internet
Author: User

Complete modification and deletion of ADO. NET and ado.net

Complete namespace Modification
{
Class Program
{
Static void Main (string [] args)
{
Bool has = false;

Console. Write ("Enter the user name to be modified :");
String Uname = Console. ReadLine ();

SqlConnection conn = new SqlConnection ("server = ..; database = Data0720; user = sa; pwd = 123 ");
SqlCommand cmd = conn. CreateCommand ();
Cmd. CommandText = "select * from Users where UserName = '" + Uname + "'";
Conn. Open ();
SqlDataReader dr = cmd. ExecuteReader ();
If (dr. HasRows)
{
Has = true;
}
Conn. Close ();

If (has)
{
Console. WriteLine ("[" + Uname + "] user information found, Please modify it ");
Console. Write ("Enter the modified password :");
String Pwd = Console. ReadLine ();
Console. Write ("Enter the nickname after modification :");
String Nname = Console. ReadLine ();
Console. Write ("Enter the modified Gender :");
String Sex = Console. ReadLine ();
Console. Write ("Enter the modified birthday :");
String Birthday = Console. ReadLine ();
Console. Write ("Enter the modified Nationality :");
String Nation = Console. ReadLine ();

// @ Key placeholder
Cmd. CommandText = "update Users set PassWord = @ pwd, NickName = @ nname, Sex = @ sex, Birthday = @ bir, Nation = @ nat where UserName = @ uname ;";
Cmd. Parameters. Clear ();
Cmd. Parameters. Add ("@ pwd", Pwd );
Cmd. Parameters. Add ("@ nname", Nname );
Cmd. Parameters. Add ("@ sex", (Sex = "male ")? "1": "0 ");
Cmd. Parameters. Add ("@ bir", Birthday );
Cmd. Parameters. Add ("@ nat", Nation );
Cmd. Parameters. Add ("@ uname", Uname );

Conn. Open ();
Cmd. ExecuteNonQuery ();
Conn. Close ();
Console. WriteLine ("modified! ");
}
Else
{
Console. WriteLine ("[" + Uname + "] user information not found. Check whether the user name is entered correctly! ");
}

Console. ReadLine ();

}

}
}

 

 

Complete namespace modification and deletion _ database String Attack
{
Class Program
{
Static void Main (string [] args)
{
Bool has = false;

Console. Write ("Enter the username to delete :");
String Uname = Console. ReadLine ();

SqlConnection conn = new SqlConnection ("server = ..; database = Data0720; user = sa; pwd = 123 ");
SqlCommand cmd = conn. CreateCommand ();
Cmd. CommandText = "select * from Users where UserName = '" + Uname + "'";
Conn. Open ();
SqlDataReader dr = cmd. ExecuteReader ();
If (dr. HasRows)
{
Has = true;
}
Conn. Close ();

If (has)
{
Console. WriteLine ("[" + Uname + "] user information has been found. Are you sure you want to delete it? (Y/N ):");
String u = Console. ReadLine ();
If (u. ToUpper () = "Y") // confirm to delete
{
Cmd. CommandText = "delete from Users where UserName = '" + Uname + "'";
Conn. Open ();
Cmd. ExecuteNonQuery ();
Conn. Close ();
Console. WriteLine (Uname + "deleted successfully! ");
}
}
Else
{
Console. WriteLine ("[" + Uname + "] user information not found. Check whether the user name is entered correctly! ");
}

Console. ReadLine ();
}
}
}

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.