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();
}
}
}
}
![]()