感谢论坛上老大为我解答,环境sql2005+vsweb2005
protected void Page_Load(object sender, EventArgs e)
{//显示数据
SqlConnection mycon = new SqlConnection();
mycon.ConnectionString = "Data Source=localhost\\SQLEXPRESS;Initial Catalog=testasp;Integrated Security=True";
mycon.Open();
SqlCommand mycmd = new SqlCommand("select * FROM Table2",mycon);
SqlDataReader sdr = mycmd.ExecuteReader();
lb1.DataSource = sdr;
lb1.DataTextField = "user_id";
lb1.DataValueField = "user_id";
lb1.DataBind();
}
protected void Button1_Click(object sender, EventArgs e)
{ // 删除数据 SqlConnection mycon = new SqlConnection();
mycon.ConnectionString = "Data Source=localhost\\SQLEXPRESS;Initial Catalog=testasp;Integrated Security=True";
mycon.Open();
SqlCommand mycmd = new SqlCommand("delete FROM Table2 where user_id < 30",mycon);
} 为什么安了删除键还删不掉呢,
protected void Page_Load(object sender, EventArgs e)
{//显示数据
SqlConnection mycon = new SqlConnection();
mycon.ConnectionString = "Data Source=localhost\\SQLEXPRESS;Initial Catalog=testasp;Integrated Security=True";
mycon.Open();
SqlCommand mycmd = new SqlCommand("select * FROM Table2",mycon);
SqlDataReader sdr = mycmd.ExecuteReader();
lb1.DataSource = sdr;
lb1.DataTextField = "user_id";
lb1.DataValueField = "user_id";
lb1.DataBind();
}
protected void Button1_Click(object sender, EventArgs e)
{ // 删除数据 SqlConnection mycon = new SqlConnection();
mycon.ConnectionString = "Data Source=localhost\\SQLEXPRESS;Initial Catalog=testasp;Integrated Security=True";
mycon.Open();
SqlCommand mycmd = new SqlCommand("delete FROM Table2 where user_id < 30",mycon);
} 为什么安了删除键还删不掉呢,
解决方案 »
- 请教一个用httpwebrequest关于登陆有验证码的网站。
- 请教怎么样设定WPF程序的图标?
- 如何在OpenSSL中使用C#产生的密钥对?
- System.Data.SqlClient.SqlException: ')' 附近有语法错误。
- 如何实现局域网之间的文件上传下载
- 如何弹出"删除"提示
- zglxh3(noproblem) ,接分啊!
- 请问表格中最下面一行的“合计”是怎么画出来的?我用的是DATAGRID,请高人指点~~~
- web页面生成如何邮件格式或jpg
- 程序在域工作组下可以正常运行,但是到了域控制器的机器下就不能运行了!!!!!!!!
- 请问怎么动态获得web services中的类名和方法名?
- C#如何用代码模拟按钮点击事件?
SqlCommand mycmd = new SqlCommand("delete FROM Table2 where user_id < 30",mycon);
mycmd.ExecuteNonQuery(); //这句后面加上这句试试
加上mycmd.ExcuteNoneQuery();
{ // 删除数据 SqlConnection mycon = new SqlConnection();
mycon.ConnectionString = "Data Source=localhost\\SQLEXPRESS;Initial Catalog=testasp;Integrated Security=True";
mycon.Open();
SqlCommand mycmd = new SqlCommand("delete FROM Table2 where user_id < 30",mycon);
} 为什么安了删除键还删不掉呢,
-------------------你创建了Command,但是没有执行啊
mycmd.ExecuteNonQuery();
mycmd.ExecuteNonQuery();
然后:
SqlCommand mycmd = new SqlCommand("select * FROM Table2",mycon);
SqlDataReader sdr = mycmd.ExecuteReader();
lb1.DataSource = sdr;
lb1.DataTextField = "user_id";
lb1.DataValueField = "user_id";
lb1.DataBind();