编程中国 | 业界新闻 | 技术文章 | 视频教程 | 下载频道 | 程序源码 | 个人空间 | 编程论坛  
全能 ASP / PHP / ASP.NET 主机,支持月付专业 MSSQL 数据库空间,支持月付专业 MySQL 数据库空间,支持月付学习型 ASP/PHP/ASP.NET 主机 30元/年
发新话题
打印

用户代码未处理SqlException 是什么一回事?(在线等)(紧急)

用户代码未处理SqlException 是什么一回事?(在线等)(紧急)

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    '='附近有错误"

TOP

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 + "'";
Flying without wings

TOP

发新话题