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 KumarRank #1,937 · 758 reputationPosted Feb 3, 2014, 2:01 AM EST
Biswa Pujarini MohapatraRank #465 · 5.4K reputationPosted Feb 3, 2014, 1:08 AM EST
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);
Rajeev KumarRank #1,937 · 758 reputationPosted Feb 3, 2014, 1:28 AM EST
ALOK SHARMA51 reputationPosted Feb 3, 2014, 1:48 AM EST
ALOK SHARMA51 reputationPosted Feb 3, 2014, 2:04 AM EST