C# 使用文本框更新SQL Express中的查询
它未显示错误,但未在数据库中更新。请尝试以下代码:C# 使用文本框更新SQL Express中的查询,c#,asp.net,sql-server,ado.net,C#,Asp.net,Sql Server,Ado.net,它未显示错误,但未在数据库中更新。请尝试以下代码: protected void Button1_Click(object sender, EventArgs e) { SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["project"].ConnectionString.ToString()); conn.Open(); string arun = "UPD
protected void Button1_Click(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["project"].ConnectionString.ToString());
conn.Open();
string arun = "UPDATE [RECEIVE] SET [RDDF2]=@RDFF2 WHERE [OIESN]=@SRT";
string SR2 = TextBox1.Text;
int SR = int.Parse(TextBox1.Text);
string SR1 = TextBox9.Text;
SqlCommand cmd = new SqlCommand();
cmd.Connection = conn;
cmd.CommandText = arun;
cmd.Parameters.AddWithValue("@SRT", SR);
cmd.Parameters.AddWithValue("@RDFF2", SR1);
cmd.ExecuteNonQuery();
conn.Close();
}
你能把try/catch放在桌子上吗。。它将帮助您进一步检查的返回值:对于UPDATE、INSERT和DELETE语句,返回值是受命令影响的行数
protected void Button1_Click(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["project"].ConnectionString.ToString());
string arun = "UPDATE [RECEIVE] SET [RDDF2]=@RDFF2 WHERE [OIESN]=@SRT";
string SR2 = TextBox1.Text;
int SR = int.Parse(TextBox1.Text);
string SR1 = TextBox9.Text;
using (SqlCommand SqlCmd = new SqlCommand(arun, conn))
{
conn.Open();
cmd.CommandType = CommandType.Text;
cmd.Parameters.Add("@SRT", SqlDbType.Int).Value = SR;
cmd.Parameters.Add("@RDFF2", SqlDbType.VarChar).Value = SR1;
cmd.ExecuteNonQuery();
conn.Close();
}
}