Please help:
i am trying to insert values with checkbox button(Active) and radiobutton (Status)
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();
}
But i am getting this error.Do i need to add coding for radiobutton list (active ) and checkbox button list(Status)
Exception Details: System.Data.SqlClient.SqlException: Incorrect syntax near '@Active'.
Thanks in advance
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'.
|
Rajeev KumarPosted Feb 3, 2014, 7:01 AM
ALOK SHARMAPosted Feb 3, 2014, 7:04 AM
ALOK SHARMAPosted Feb 3, 2014, 6:48 AM
Rajeev KumarPosted Feb 3, 2014, 6:28 AM
Biswa Pujarini MohapatraPosted Feb 3, 2014, 6:08 AM
no you have missed closed braces after @active
here is your code
SqlCommand cmd = new SqlCommand("insert into Edittable(Name,Address,Department,Salary,Status,Active)values(@Name,@Address,@Department,@Salary,@Status,@Active)", con);