您的位置:首页 > 其它

ado删除

2016-06-21 18:26 351 查看
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.SqlClient;

namespace ConsoleApplication5
{
class Program
{
static void Main(string[] args)
{
//1、提示用户输入需要删除的行的学号是多少
Console.Write("请输入您需要删除的学号:");
string scode = Console.ReadLine();//删除s101
//2、执行操作
//引用数据库命名空间
//建立数据连接
SqlConnection conn = new SqlConnection("server=.;database=data0425;user=sa;pwd=123");
//建立数据操作
SqlCommand cmd = conn.CreateCommand();
//编写sql操作命令
cmd.CommandText = "delete  from student where code='"+scode+"'";
try
{
//开启数据库
conn.Open();
//执行操作命令
cmd.ExecuteNonQuery();
Console.WriteLine("删除成功!");
}
catch
{
Console.WriteLine("连接数据库失败!请重新连接!");
}
finally
{
//关闭数据库
conn.Close();
Console.ReadLine();
}

}
}
}


内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: