Я пытаюсь переключиться с моих запросов SQL на запросы параметров, но я продолжаю получать некоторые ошибки, показанные после кода ниже:
protected void btnSubmit_Click(object sender, EventArgs e)
{
if (Page.IsValid)
{
//Define data objects
SqlConnection conn;
//SqlCommand comm;
//Read the connection string from web config
string connectionString = ConfigurationManager.ConnectionStrings["clientsConnectionString"].ConnectionString;
//Initialize the connection
conn = new SqlConnection(connectionString);
//Create Command
// comm = new SqlCommand();
const string SQL = "insert into request (Surname,[Other Names], mobileno, date, email, faculty, dept, [Registration Number], session, thesis, yearGrad, tellerno, amount, address, question ) values (@Surname,[@Other Names],@mobileno,@date, @email, @faculty, @dept, [@Registration Number], @session,@thesis, @yearGrad, @tellerno, @amount, @address,@question)";
SqlCommand cmd = new SqlCommand(SQL, conn);
cmd.Parameters.AddWithValue("@Surname", lblSurname.Text);
cmd.Parameters.AddWithValue("@[Other Names]", lblOtherNames.Text);
cmd.Parameters.AddWithValue("@mobileno", lblPhone.Text);
cmd.Parameters.AddWithValue("@date", lblDate.Text);
cmd.Parameters.AddWithValue("@email", lblEmail.Text);
cmd.Parameters.AddWithValue("@faculty", lblFaculty.Text);
cmd.Parameters.AddWithValue("@dept", lblDept.Text);
cmd.Parameters.AddWithValue("@[Registration Number]", lblRegNo.Text);
cmd.Parameters.AddWithValue("@session", lblSession.Text);
cmd.Parameters.AddWithValue("@thesis", lblThesis.Text);
cmd.Parameters.AddWithValue("@yearGrad", lblGradYr.Text);
cmd.Parameters.AddWithValue("@tellerno", lblTeller.Text);
cmd.Parameters.AddWithValue("@amount", lblAmount.Text);
cmd.Parameters.AddWithValue("@address", lblAdd.Text);
cmd.Parameters.AddWithValue("@question", lblQue.Text);
conn.Open();
// verify if the ID entered by the visitor is numeric
cmd.ExecuteNonQuery();
conn.Close();
//reload page if query executed succesfully
Response.Redirect("thanks.aspx");
}
}
Сообщение об ошибке:
Ошибка сервера в приложении / TranscriptReloaded.
Неверный синтаксис рядом с 'nvarchar'.
Должен объявить скалярную переменную "@date".