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)
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'.
[SqlException (0x80131904): Incorrect syntax near '@Active'.] System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection) +2030802 System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) +5009584 System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning() +234 System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) +2275 System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString) +215 System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async) +987 System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result) +162 System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(DbAsyncResult result, String methodName, Boolean sendToPipe) +178 System.Data.SqlClient.SqlCommand.ExecuteNonQuery() +137 _Default.txtSubmit_Click(Object sender, EventArgs e) +445 System.Web.UI.WebControls.Button.OnClick(EventArgs e) +118 System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +112 System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10 System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13 System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5563
|