![]() |
#2
冰彩虹2008-06-22 06:31
protected void Button2_Click(object sender, EventArgs e)
{ SqlConnection conn = new SqlConnection(@"Data Source=AISN\SQLEXPRESS;AttachDbFilename=D:\4246\data\computer.mdf;Integrated Security=True"); try{ conn.Open(); string strsql = "select * from Vuser_Information where Vuser_ID=" + DropDownList1.SelectedValue; SqlDataAdapter ad = new SqlDataAdapter(strsql, conn); SqlCommandBuilder cmb = new SqlCommandBuilder(ad); DataSet ds = new DataSet(); ad.Fill(ds, "Vuser_Information"); DataTable dt = ds.Tables["Vuser_Information"]; DataRow row = dt.NewRow(); row["Vuser_ID"] = TextBox1.Text; row["Vuser_name"] = TextBox2.Text; row["Vuser_Sex"] = TextBox3.Text; row["Vuser_Address"] = TextBox4.Text; row["Vuser_Password"] = TextBox5.Text; row["Vuser_Spending"] = TextBox6.Text; row["Vuser_Remarks"] = TextBox7.Text; dt.Rows.Add(row); ad.Update(ds, "Vuser_Information"); Panel1.Visible = false; DropDownList1_content(); GridView1_content(); catch(Exception ex) { //handler the exception } } 你数据表里Vuser_ID是什么类型,不是int类型的话, string strsql = "select * from Vuser_Information where Vuser_ID= ‘" + DropDownList1.SelectedValue + "'"; |
protected void Button2_Click(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection(@"Data Source=AISN\SQLEXPRESS;AttachDbFilename=D:\4246\data\computer.mdf;Integrated Security=True");
conn.Open();
string strsql = "select * from Vuser_Information where Vuser_ID=" + DropDownList1.SelectedValue;
SqlDataAdapter ad = new SqlDataAdapter(strsql, conn);
SqlCommandBuilder cmb = new SqlCommandBuilder(ad);
DataSet ds = new DataSet();
ad.Fill(ds, "Vuser_Information");
DataTable dt = ds.Tables["Vuser_Information"];
DataRow row = dt.NewRow();
row["Vuser_ID"] = TextBox1.Text;
row["Vuser_name"] = TextBox2.Text;
row["Vuser_Sex"] = TextBox3.Text;
row["Vuser_Address"] = TextBox4.Text;
row["Vuser_Password"] = TextBox5.Text;
row["Vuser_Spending"] = TextBox6.Text;
row["Vuser_Remarks"] = TextBox7.Text;
dt.Rows.Add(row);
ad.Update(ds, "Vuser_Information");
Panel1.Visible = false;
DropDownList1_content();
GridView1_content();
}
这个是也添加按钮.
但是一按这个按钮就提示 "用户代码未处理SqlException '='附近有错误"