Hi there

I want to know how I can save a checkbox value into sql server 2005? The check box is in my windows forms application...

Thanks

Which value you want to store?

To store string/varchar then store the relevant data into memory variables and write them into database via ADO.NET API.

string result="No";
  if(checkBox1.Checked)
     result="Yes";
  .....

I want to store both values, checked or not checked...

Also, How do I fill a checkbox with the value stored in the database?

Consider the following example.

A table "sample" has two columns. Field types of these columns is "bit".

SqlConnection cn=new SqlConnection("connection_string_here");
  SqlCommand cmd=new SqlCommand();
  cmd.Connection=cn;
  cmd.CommandText="insert into sample values (@p1,@p2)";
  cmd.Parameters.AddWithValue("@p1",checkBox1.Checked);
  cmd.Parameters.AddWithValue("@p2",checkBox2.Checked);
  cn.Open();
  cmd.ExecuteNonQuery();
  cn.Close();
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.