Im trying to query an UPDATE for my database, and it gives me an error :
The parameterized query '(@naming nvarchar(7),@role nvarchar(3),@company nvarchar(3),@sal' expects the parameter '@link_company', which was not supplied.
This is my code :
<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>
and this is my code behind :
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");
}
and this is my "UpdateManager" function :
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();
}
When I tried to run this query on my SQL management tool , it runs ok. and NO column is required (any column except of the ID..) allowing null..which is weird..
any thoughts ?