how to get the selected value of check-box in asp.net

I am trying to get the selected value of the check-box but it is always showing zero in the back-end table even when i select the check-box. The data type for the check-box is bit. I am not sure what am i doing wrong here.
 using (SqlConnection con = new SqlConnection(strConnString))
            {
                using (SqlCommand cmd = new SqlCommand(@"insert into myTable(UserID, Name) values( @UserID, @Name)"))                                                                                            

                {
                    using (SqlDataAdapter sda = new SqlDataAdapter())
                    {
                        cmd.CommandType = CommandType.Text;
                        cmd.Parameters.AddWithValue("@UserID", tempUser.ToString());

                        cmd.Parameters.AddWithValue("@Name", chckNM.Checked);

                        cmd.Connection = con;
                        con.Open();
                        cmd.ExecuteNonQuery();

                    }

Open in new window

here is the checkbox
<asp:CheckBox ID="chckNM" runat="server" />

Open in new window

moe57Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Peter HutchisonSenior Network Systems SpecialistCommented:
Try this code:
if (chck.Checked )
   cmd.Parameters.AddWithValue("@Name", True);
else
   cmd.Parameters.AddWithValue("@Name", False);

Assuming the @Name field is a Boolean value or integer value. If its a text value then change the values to "True" and "False"
with the quotes.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
moe57Author Commented:
thanks
0
moe57Author Commented:
sorry even though i closed the question but i hope you could help me.  I want to retrieve the data and this is the syntax i am want to use but it is not quite right yet
checkNM.value = dtSETS_row.Field<bool>("Name");

Open in new window

when the page loads, i want the checkbox to show whatever value in the database but the chckNM.value is not working for me..
0
Peter HutchisonSenior Network Systems SpecialistCommented:
Change the line to:
checkNM.Checked = dtSETS_row.Field<bool>("Name");
0
moe57Author Commented:
thanks
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.