读书人

c# update,该如何处理

发布时间: 2012-06-15 19:37:05 作者: rapoo

c# update
我的这个页面是一个修改页面
页面的内容是获取上个页面textbox的值显示出来的,用的是textbox
内容可以添加或者修改,我的cs代码页写好了,也没有错误,但是就是没有反应
麻烦各位帮我看下有什么问题
protected void Button1_Click(object sender, EventArgs e)
{
if (Session["ABC"] != null)
Label44.Text = Session["ABC"].ToString();

string x = Label44.Text;

string z = TextBox1.Text;

string b = TextBox2.Text;

string c = TextBox3.Text;

string d = TextBox4.Text;

string s = TextBox5.Text;

string k = TextBox6.Text;

string g = TextBox7.Text;

string f = TextBox8.Text;


string i = TextBox9.Text;

string y = TextBox10.Text;

string m = TextBox11.Text;

string n = TextBox12.Text;

string o = TextBox13.Text;

string p = TextBox14.Text;
string q = TextBox15.Text;

string r = TextBox16.Text;
string t = TextBox17.Text;

OleDbConnection conn = new OleDbConnection();
conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|db1.mdb";
OleDbCommand comm = new OleDbCommand();
conn.Open();
comm.Connection = conn;

comm.CommandText = "UPDATE [userdetail] SET [username]='" + z + "',[sex]='" + b + "',[age]='" + c + "',[nativeplace]='" + d + "',[tel]='" + s + "',[email]='" + k + "',[xueli]='" + g + "',[school]='" + f + "',[position]='" + i + "',[english]='" + y + "',[jybj]='" + m + "',[gzjl]='" + n + "',[zytc]='" + o + "',[zycg]='" + p + "',[jtqk]='" + q + "',[xqah]='" + r + "',[qzyx]='" + t + "' WHERE [tel] ='" + x + "'";

comm.Parameters.AddWithValue("@username", z);
comm.Parameters.AddWithValue("@sex", b);
comm.Parameters.AddWithValue("@age", c);
comm.Parameters.AddWithValue("@nativeplace", d);
comm.Parameters.AddWithValue("@tel", s);
comm.Parameters.AddWithValue("@email", k);
comm.Parameters.AddWithValue("@xueli", g);
comm.Parameters.AddWithValue("@school", f);
comm.Parameters.AddWithValue("@position", i);
comm.Parameters.AddWithValue("@english", y);
comm.Parameters.AddWithValue("@jybj", m);

comm.Parameters.AddWithValue("@gzjl", n);
comm.Parameters.AddWithValue("@zytc", o);
comm.Parameters.AddWithValue("@zycg", p);
comm.Parameters.AddWithValue("@jtqk", q);
comm.Parameters.AddWithValue("@xqah", r);
comm.Parameters.AddWithValue("@qzyx", t);

comm.ExecuteNonQuery();
conn.Close();







}
}



[解决办法]

探讨

你既然用的参数化,sql语句这样写
comm.CommandText = "UPDATE [userdetail] SET [username]=@username";//后面也一样

还有你确定数据库连接字符串写对了

读书人网 >asp.net

热点推荐