第 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>");
}
}
请各位大侠帮忙看看出了什么问题,谢了 展开
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>");
}
}
请各位大侠帮忙看看出了什么问题,谢了 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询