ADO.NET删除和修改

using System.Data.SqlClient;

Console.Write("请输入要删除的编号:");
string ucode = Console.ReadLine();

SqlConnection conn = new SqlConnection("server=.;database=Data0504;user=sa;pwd=123;");
SqlCommand cmd = conn.CreateCommand();
cmd.CommandText = "delete from Users where Ucode='" + ucode + "'";
conn.Open();
int count = cmd.ExecuteNonQuery();
conn.Close();
if (count > 0)
{
Console.WriteLine("删除成功");
}
else
{
Console.WriteLine("删除失败!");
}
Console.ReadLine();

Console.Write("请输入您想改的内容:");
string ucode = Console.ReadLine();
string sql = "server=.;database=Data0504;user=sa;pwd=123";
SqlConnection conn = new SqlConnection(sql);
SqlCommand cmd = conn.CreateCommand();
cmd.CommandText = "update Users set NickName ='" + ucode + "' where NickName='李四'";
conn.Open();
int count = cmd.ExecuteNonQuery();
conn.Close();

if (count > 0)
{
Console.WriteLine("更改成功");
}
else
{
Console.WriteLine("更改失败!");
}
Console.ReadLine();

 

posted @ 2017-07-05 20:32  小程序员//  阅读(125)  评论(0编辑  收藏  举报