I used the Parametarized Query to save the data to sql server. When executing it throws below error.
The parameterized query '(@CustomerID int,@SerialNo nvarchar(2),@ModelNo nvarchar(2),@Sal' expects the parameter '@CreatedBy', which was not supplied.
here is my code.
public static bool SaveSales(int custid, string model, string serial, DateTime salesdate, decimal price, string mainservice, string comments, DateTime createddate, string createdby, DateTime modifieddate, string modifiedby)
{
bool saved = false;
try
{
using (SqlConnection conn = new SqlConnection(DBManager.DBConnection))
{
conn.Open();
using (var command = conn.CreateCommand())
{
command.CommandText = "INSERT INTO tbl_Sales VALUES(@CustomerID, @SerialNo, @ModelNo, @SalesDate, @Price, @MaintanenceService, @Comments, @CreatedDate, @CreatedBy, @ModifiedDate, @ModifiedBy)";
command.CommandType = CommandType.Text;
command.Parameters.AddWithValue("@CustomerID", custid);
command.Parameters.AddWithValue("@SerialNo", serial);
command.Parameters.AddWithValue("@ModelNo", model);
command.Parameters.AddWithValue("@SalesDate", salesdate);
command.Parameters.AddWithValue("@Price", price);
command.Parameters.AddWithValue("@MaintanenceService", mainservice);
command.Parameters.AddWithValue("@Comments", comments);
command.Parameters.AddWithValue("@CreatedDate", createddate);
command.Parameters.AddWithValue("@CreatedBy", createdby);
command.Parameters.AddWithValue("@ModifiedDate", modifieddate);
command.Parameters.AddWithValue("@ModifiedBy", modifiedby);
command.ExecuteNonQuery();
}
conn.Close();
}
saved = true;
}
catch (SqlException ex)
{
MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
return saved;
}
return saved;
}
What is the wrong with my query ? I used paramerized query is to save the salesdate correctly. Any help would be much appreciated.