ADO.NET 删除数据

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();

//这里记得添加命名空间 using System.Data.SqlClient;
posted @ 2017-07-08 12:27  御风飞舞  阅读(339)  评论(0编辑  收藏  举报