我试图查询我的数据库的UPDATE,它给了我一个错误:
参数化查询'(@naming nvarchar(7),@ role nvarchar(3),@ company nvarchar(3),@ sal'需要参数'@link_company',这是未提供的。
这是我的代码:
<tr>
<td><input type="text" name="name" value=" <%=dt.Rows[0][1].ToString() %>" /></td>
<td><input type="text" name="role" value=" <%=dt.Rows[0][2].ToString() %>" /></td>
<td><input type="text" name="company" value=" <%=dt.Rows[0][3].ToString() %>" /></td>
<td><input type="text" name="salary_year" value=" <%=dt.Rows[0][4].ToString() %>" /></td>
<td><input type="text" name="bonus" value=" <%=dt.Rows[0][5].ToString() %>" /></td>
<td><input type="text" name="stock" value=" <%=dt.Rows[0][6].ToString() %>" /></td>
<td><input type="text" name="other" value=" <%=dt.Rows[0][7].ToString() %>" /></td>
<td><input type="text" name="alut_year" value=" <%=dt.Rows[0][8].ToString() %>" /></td>
<td><input type="text" name="alut_monthly" value=" <%=dt.Rows[0][9].ToString() %>" /></td>
<td><input type="text" name="net" value=" <%=dt.Rows[0][10].ToString() %>" /></td>
<td><input type="text" name="link_name" value=" <%=dt.Rows[0][11].ToString() %>" /></td>
<td><input type="text" name="link_company" value=" <%=dt.Rows[0][12].ToString() %>" /></td>
<td><input type="text" name="last_year_alut" value=" <%=dt.Rows[0][13].ToString() %>" /></td>
<td><input type="text" name="avg_salary" value=" <%=dt.Rows[0][14].ToString() %>" /></td>
<td><input type="text" name="last_year_profit" value=" <%=dt.Rows[0][15].ToString() %>" /></td>
</tr>
这是我背后的代码:
string name = Request.Form["name"];
string role = Request.Form["role"];
string company = Request.Form["company"];
string salary_year = Request.Form["salary_year"];
string bonus = Request.Form["bonus"];
string stock = Request.Form["stock"];
string other = Request.Form["other"];
string alut_year = Request.Form["alut_year"];
string alut_monthly = Request.Form["alut_monthly"];
string net = Request.Form["net"];
string link_name = Request.Form["link_name"];
string link_company = Request.Form["link_comapny"];
string avg_salary = Request.Form["avg_salary"];
string last_year_profit = Request.Form["last_year_profit"];
string last_year_alut = Request.Form["last_year_alut"];
if (IsPostBack)
{
sq.UpdateManager(update,name, role, company, salary_year, bonus, stock, other, alut_year, alut_monthly, net, link_name, link_company,last_year_profit, last_year_alut, avg_salary);
Response.Redirect("insert.aspx");
}
这是我的“UpdateManager”功能:
public void UpdateManager(string id, string name, string role, string company, string salary_year, string bonus, string stock, string other, string alut_year, string alut_monthly, string net, string link_name, string link_company, string last_year_profit, string last_year_alut, string avg_salary)
{
sql = "Update table_salary SET f_name =@naming , role_manager = @role, COMPANY = @company, SALARY_YEAR =@salary_year ,BONUSING = @bonus,STOCK =@stock ,OTHER = @other, ALUT_YEAR =@alut_year,ALUT_MONTH=@alut_monthly,NET_INCOME=@net,link_name = @link_name, link_company= @link_company,LAST_YEAR_ALUT=@last_year_alut, AVG_SALARY=@avg_salary, LAST_YEAR_PROFIT=@last_year_profit where id =" + id;
connection = new SqlConnection(conn);
connection.Open();
cmd = new SqlCommand(sql, connection);
cmd.Parameters.AddWithValue("@naming", name);
cmd.Parameters.AddWithValue("@role", role);
cmd.Parameters.AddWithValue("@company", company);
cmd.Parameters.AddWithValue("@salary_year", salary_year);
cmd.Parameters.AddWithValue("@bonus", bonus);
cmd.Parameters.AddWithValue("@stock", stock);
cmd.Parameters.AddWithValue("@other", other);
cmd.Parameters.AddWithValue("@alut_year", alut_year);
cmd.Parameters.AddWithValue("@alut_monthly", alut_monthly);
cmd.Parameters.AddWithValue("@net", net);
cmd.Parameters.AddWithValue("@link_name", link_name);
cmd.Parameters.AddWithValue("@link_company", link_company);
cmd.Parameters.AddWithValue("@avg_salary", avg_salary);
cmd.Parameters.AddWithValue("@last_year_profit", last_year_profit);
cmd.Parameters.AddWithValue("@last_year_alut", last_year_alut);
cmd.ExecuteNonQuery();
connection.Close();
}
当我尝试在我的SQL管理工具上运行此查询时,它运行正常。和NO列是必需的(除了ID之外的任何列..)允许null..which很奇怪..
有什么想法吗?
答案 0 :(得分:0)
拼写错误Request.Form [“link_comapny”];