【发布时间】:2013-06-03 14:04:08
【问题描述】:
protected void Button1_Click(object sender, EventArgs e)
{
SqlConnection mycon = new SqlConnection("Data Source=127.0.0.1;Initial Catalog=master;Integrated Security=True");
SqlDataAdapter myadp = new SqlDataAdapter();
myadp.UpdateCommand = new SqlCommand("Update [orgs] Set [fname]=@fname,[weblnk]=@weblnk,[email]=@email,[cntct]=@cntct,[lctn]=@lctn,[cdscrptn]=@cdscrptn,[bsnstp]=@bsnstp WHERE [cmpny]=" +Label1.Text,mycon);
myadp.UpdateCommand.Parameters.Add("@fname", SqlDbType.VarChar, 50).Value = TextBox1.Text;
myadp.UpdateCommand.Parameters.Add("@weblnk", SqlDbType.VarChar,80).Value = TextBox3.Text;
myadp.UpdateCommand.Parameters.Add("@email", SqlDbType.VarChar,80).Value = TextBox4.Text;
myadp.UpdateCommand.Parameters.Add("@cntct", SqlDbType.VarChar,20).Value = TextBox5.Text;
myadp.UpdateCommand.Parameters.Add("@lctn", SqlDbType.VarChar,80).Value = TextBox6.Text;
myadp.UpdateCommand.Parameters.Add("@cdscrptn", SqlDbType.VarChar,600).Value = TextBox7.Text;
myadp.UpdateCommand.Parameters.Add("@bsnstp", SqlDbType.VarChar,40).Value = TextBox8.Text;
myadp.UpdateCommand.Connection = mycon;
mycon.Open();
myadp.UpdateCommand.ExecuteNonQuery();
mycon.Close();
}
protected void Button1_Click(object sender, EventArgs e)
{
SqlConnection mycon = new SqlConnection("Data Source=127.0.0.1;Initial Catalog=master;Integrated Security=True");
SqlDataAdapter myadp = new SqlDataAdapter();
myadp.UpdateCommand = new SqlCommand("Update [orgs] Set [fname]=@fname,[weblnk]=@weblnk,[email]=@email,[cntct]=@cntct,[lctn]=@lctn,[cdscrptn]=@cdscrptn,[bsnstp]=@bsnstp WHERE [cmpny]=@cmpny", mycon);
myadp.UpdateCommand.Parameters.Add("@fname", SqlDbType.VarChar, 50).Value = TextBox1.Text;
myadp.UpdateCommand.Parameters.Add("@cmpny", SqlDbType.VarChar, 50).Value = TextBox2.Text;
myadp.UpdateCommand.Parameters.Add("@weblnk", SqlDbType.VarChar,80).Value = TextBox3.Text;
myadp.UpdateCommand.Parameters.Add("@email", SqlDbType.VarChar,80).Value = TextBox4.Text;
myadp.UpdateCommand.Parameters.Add("@cntct", SqlDbType.VarChar,20).Value = TextBox5.Text;
myadp.UpdateCommand.Parameters.Add("@lctn", SqlDbType.VarChar,80).Value = TextBox6.Text;
myadp.UpdateCommand.Parameters.Add("@cdscrptn", SqlDbType.VarChar,600).Value = TextBox7.Text;
myadp.UpdateCommand.Parameters.Add("@bsnstp", SqlDbType.VarChar,40).Value = TextBox8.Text;
myadp.UpdateCommand.Connection = mycon;
mycon.Open();
myadp.UpdateCommand.ExecuteNonQuery();
mycon.Close();
}
这里我也对cmpny 进行了参数化,但它仍然无法正常工作
【问题讨论】:
-
任何错误或异常?
-
你也应该参数化
cmpny。 -
不工作?你有什么异常吗?
-
描述更多你所面临的错误......我们无法在没有解释的情况下帮助你
-
您正在连接到主数据库?你确定这就是你想要的吗?
标签: c# asp.net sqlcommand