I am trying to insert values but getting error at checkbox button as
Exception Details: System.Data.SqlClient.SqlException: Incorrect syntax near '@Active'.
protected void txtSubmit_Click(object sender, EventArgs e)
Incorrect syntax near '@Active'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.Exception Details: System.Data.SqlClient.SqlException: Incorrect syntax near '@Active'.
|
protected void txtSubmit_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(@"Data Source=SONY-VAIO\SQLEXPRESS;Initial Catalog=Employee;Integrated Security=True");
con.Open();
SqlCommand cmd = new SqlCommand("insert into Edittable(Name,Address,Department,Salary,Status,Active)values(@Name,@Address,@Department,@Salary,@Status,@Active", con);
cmd.Parameters.AddWithValue("@Id", txtId.Text.ToString());
cmd.Parameters.AddWithValue("@Name", txtName.Text.ToString());
cmd.Parameters.AddWithValue("@Address", txtAddress.Text.ToString());
cmd.Parameters.AddWithValue("@Department", ddlDepartment.SelectedValue.ToString());
cmd.Parameters.AddWithValue("@Salary", txtSalary.Text.ToString());
cmd.Parameters.AddWithValue("@Active", ChkActive.SelectedItem.ToString());
cmd.Parameters.AddWithValue("@Status", rdStatus.SelectedItem.ToString());
cmd.ExecuteNonQuery();
}
VulpesPosted Feb 3, 2014, 6:40 AM
However, you have done that subject to adding the closing bracket after @Active.
Are you sure it's no better after you've done that?
ALOK SHARMAPosted Feb 3, 2014, 6:24 AM
VulpesPosted Feb 3, 2014, 6:05 AM
SqlCommand cmd = new SqlCommand("insert into Edittable(Name,Address,Department,Salary,Status,Active)
values(@Name,@Address,@Department,@Salary,@Status,@Active)", con);