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

详细的usingSystem;usingSystem.Data;usingSystem.Configuration;usingSystem.Collections;usi... 详细的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>");
}
}
请各位大侠帮忙看看出了什么问题,谢了
展开
 我来答
成如心7O
2009-07-30 · TA获得超过407个赞
知道小有建树答主
回答量:679
采纳率:0%
帮助的人:404万
展开全部
填充表名把〔〕去掉试试 sda.Fill(ds, "[User]");

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

仔细查看SQL表达式

代码还是需要优化呀。
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式