System.Data.SqlClient.SqlException: 第 1 行: '*' 附近有语法错误。
在SQL中student表已经建好了,还可以查询,由于是要删除学生的信息所以我采用了绑定,可是绑定成功了,但是在删除时出问题了。说什么System.Data.SqlCli...
在SQL中student表已经建好了,还可以查询,由于是要删除学生的信息所以我采用了绑定,可是绑定成功了,但是在删除时出问题了。说什么System.Data.SqlClient.SqlException: 第 1 行: '*' 附近有语法错误。
程序是这样的:
using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class Del : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
MyBind();//调用MyBind()方法
}
}
private void MyBind()
{
String strCon = "server=localhost;uid=sa;pwd=;database=SY2060721";
SqlConnection con = new SqlConnection(strCon);
SqlCommand cmd = con.CreateCommand();
cmd.CommandText = "select sno from student order by sno asc";
con.Open();
SqlDataReader dr = cmd.ExecuteReader();
sno.DataSource = dr;
sno.DataTextField = "sno";
sno.DataBind();
con.Close();
}
protected void Button1_Click(object sender, EventArgs e)
{
String strCon = "server=localhost;uid=sa;pwd=;database=SY2060721";
SqlConnection con = new SqlConnection(strCon);
SqlCommand cmd = con.CreateCommand();
cmd.CommandText = "delete *from student where sno=" +Convert.ToInt16(sno.SelectedItem.Text);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
MyBind();
Response.Redirect("Default.aspx");
}
}
那位帮我搞定啊,我都快逼疯了,弄那么久都没出来!!! 展开
程序是这样的:
using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class Del : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
MyBind();//调用MyBind()方法
}
}
private void MyBind()
{
String strCon = "server=localhost;uid=sa;pwd=;database=SY2060721";
SqlConnection con = new SqlConnection(strCon);
SqlCommand cmd = con.CreateCommand();
cmd.CommandText = "select sno from student order by sno asc";
con.Open();
SqlDataReader dr = cmd.ExecuteReader();
sno.DataSource = dr;
sno.DataTextField = "sno";
sno.DataBind();
con.Close();
}
protected void Button1_Click(object sender, EventArgs e)
{
String strCon = "server=localhost;uid=sa;pwd=;database=SY2060721";
SqlConnection con = new SqlConnection(strCon);
SqlCommand cmd = con.CreateCommand();
cmd.CommandText = "delete *from student where sno=" +Convert.ToInt16(sno.SelectedItem.Text);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
MyBind();
Response.Redirect("Default.aspx");
}
}
那位帮我搞定啊,我都快逼疯了,弄那么久都没出来!!! 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询