c#中的更新命令

时间:2015-09-05 06:21:51

标签: sql sql-server c#-3.0

这是一个简单的更新代码。但是这段代码没有更新我的表格。

static string db = (System.Web.Configuration.WebConfigurationManager.ConnectionStrings["strcon"].ConnectionString);

SqlConnection connect = new SqlConnection(db);
connect.Open();

string Command = "Update Order Set Name = @Name, Apple_gmail_id = @Apple_gmail_id, Apple_gmail_Pass = @Apple_gmail_Pass, Mobilenumber  = @Mobilenumber, VillageName = @VillageName, VillageDegree = @VillageDegree, CountOfGem = @CountOfGem, Amount = @Amount WHERE Order_ID = @Order_ID";

SqlCommand cmdIns = new SqlCommand(Command, connect);

cmdIns.Parameters.AddWithValue("@Name", GetDataValue(TextBox1.Text));
cmdIns.Parameters.AddWithValue("@Apple_gmail_id", GetDataValue(TextBox2.Text));
cmdIns.Parameters.AddWithValue("@Apple_gmail_Pass", GetDataValue(TextBox3.Text));
cmdIns.Parameters.AddWithValue("@Mobilenumber", GetDataValue(TextBox4.Text));
cmdIns.Parameters.AddWithValue("@VillageName", GetDataValue(TextBox5.Text));
cmdIns.Parameters.AddWithValue("@VillageDegree", GetDataValue(TextBox6.Text));
cmdIns.Parameters.AddWithValue("@CountOfGem", radio);
cmdIns.Parameters.AddWithValue("@Amount", GetDataValue(txtmab.Text));

cmdIns.ExecuteNonQuery();
connect.Close();

这是我在web.config中连接数据库的代码:

<connectionStrings>
    <add name="strcon" 
         connectionString="Server=.;Database=Gem;Integrated Security=True;" />
</connectionStrings>

1 个答案:

答案 0 :(得分:0)

您忘记为@Order_ID子句中指定的WHERE添加参数。