本文介绍了在Update语句上混淆的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
HI,
我创建了一个带有textboses和数据库的Web表单。我现在很困惑.....
I have created a web form with textboses and a database. I am confused now.....
when i created a table, i created it with UserID column and set primary key but on the web form i didnt included it..so i dont know if i must include it..if yes? can u please show me how as i have already done the coding
你可以告诉我,我必须作为初学者提高。
在下面找到我的代码..
You are allowed to tell me were i must improve as a begginer.
find my code below..
protected void btnUpdate_Click(object sender, EventArgs e)
{
try
{
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString01"].ConnectionString);
conn.Open();
SqlCommand comm = new SqlCommand("Udate tblreg");
comm.ExecuteNonQuery();
txtuser.Text = "";
txtPass.Text = "";
txtFulln.Text = "";
txtSurname.Text = "";
txtemail.Text = "";
dropCountry.SelectedItem.ToString();
dropProvince.SelectedItem.ToString();
conn.Close();
Label1.Visible = true;
Label1.Text = "Record Successfully Updated!!";
}
catch
{
Response.Write("Error Occurred!!");
}
finally
{
Response.Write("Executed");
}
}
}
推荐答案
using (SqlConnection con = new SqlConnection(strConnect))
{
con.Open();
using (SqlCommand com = new SqlCommand("UPDATE myTable SET myColumn1=@C1, myColumn2=@C2 WHERE Id=@ID", con))
{
com.Parameters.AddWithValue("@ID", id);
com.Parameters.AddWithValue("@C1", myValueForColumn1);
com.Parameters.AddWithValue("@C2", myValueForColumn2);
com.ExecuteNonQuery();
}
}
这篇关于在Update语句上混淆的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!