第 1 行: '(' 附近有语法错误。用户代码未处理sqlexecption

详细的using System;
using System.Data;
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;
using System.Data.SqlClient;

public partial class User_page3 : System.Web.UI.Page
{
public void aa()
{
SqlConnection con = new SqlConnection();
con.ConnectionString = "server=(local);uid=sa;pwd=password;database=ss;";
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "select * from [User]";
cmd.Connection = con;
SqlDataAdapter sda = new SqlDataAdapter();
sda.SelectCommand = cmd;
con.Open();
DataSet ds = new DataSet();
sda.Fill(ds, "[User]");
con.Close();
this.GridView1.DataSourceID = null;
this.GridView1.DataSource = ds;
this.GridView1.DataBind();

}
protected void Page_Load(object sender, EventArgs e)
{
this.aa();
}
protected void Button1_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection();
con.ConnectionString = "server=(local);uid=sa;pwd=password;database=ss;";
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "insert into [User](姓名,部门) values('" + this.TextBox1.Text + "','" + this.TextBox2.Text + "')";
cmd.Connection = con;
con.Open();
SqlDataReader sdr = cmd.ExecuteReader();
this.GridView1.DataSource = sdr;
this.GridView1.DataBind();
con.Close();
Response.Write("<script>alert(\"已保存!\");window.location.href='User page3.aspx';</script>");
}
protected void Button2_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection();
con.ConnectionString = "server=(local);uid=sa;pwd=password;database=ss;";
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "delete from [User](姓名,部门) where id=" + this.TextBox1.Text + " ";
cmd.Connection = con;
con.Open();
SqlDataReader sdr = cmd.ExecuteReader();
this.GridView1.DataSource = sdr;
this.GridView1.DataBind();
con.Close();
Response.Write("<script>alert(\"已删除!\");window.location.href='User page3.aspx';</script>");
}
}
请各位大侠帮忙看看出了什么问题,谢了

填充表名把〔〕去掉试试 sda.Fill(ds, "[User]");

我在电脑上帮你试了,可没有SQL,我用的是ACCESS,,你要好好调试,看一下错误信息,最好把错误发出来,

仔细查看SQL表达式

代码还是需要优化呀。
温馨提示:答案为网友推荐,仅供参考
相似回答
大家正在搜