using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Data.SqlClient; namespace ado删除 { class Program { static void Main(string[] args) { //1、要删除的学生学号 Console.Write("请输入要删除的学生编号:"); string Scode = Console.ReadLine(); //2、执行删除 SqlConnection conn = new SqlConnection("server=.;database=banji0425;user=sa;pwd=123;"); SqlCommand cmd = conn.CreateCommand(); cmd.CommandText = "delete from gongsi where code = '" + Scode + "'"; try { conn.Open(); cmd.ExecuteNonQuery(); Console.WriteLine("删除成功!"); } catch { Console.WriteLine("服务器连接失败!删除失败!"); } finally { conn.Close(); Console.ReadLine(); } } } }
四、删除数据
cmd.ExecuteNonQuery();