Making a checked or unchecked checkbox insert a number 1 or 0 into database

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
hi guys, i have this database that has to interact with my C# form, but how am I going to convert a checkbox.checked into a Boolean which will infact return a 0 or 1 in one column and at the same time a Yes or No in the other column?
here is my code:
<span style="font-size:small


<span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small private<span style="font-size:small
<span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small void<span style="font-size:small button2_Click(<span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small object<span style="font-size:small
sender, <span style="color:#2b91af; font-size:small <span style="color:#2b91af; font-size:small EventArgs<span style="font-size:small e)
<span style="font-size:small
{


<span style="color:#2b91af; font-size:small <span style="color:#2b91af; font-size:small SqlConnection<span style="font-size:small conn =
<span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small new<span style="font-size:small
<span style="color:#2b91af; font-size:small <span style="color:#2b91af; font-size:small SqlConnection<span style="font-size:small (<span style="color:#a31515; font-size:small <span style="color:#a31515; font-size:small "database=KnowledgeEssentials;Trusted_Connection=yes;connection
timeout=30"<span style="font-size:small );
<span style="font-size:small


<span style="color:#2b91af; font-size:small <span style="color:#2b91af; font-size:small SqlDataAdapter<span style="font-size:small da =
<span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small new<span style="font-size:small
<span style="color:#2b91af; font-size:small <span style="color:#2b91af; font-size:small SqlDataAdapter<span style="font-size:small ();
<span style="font-size:small
da.InsertCommand =


<span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small new<span style="font-size:small
<span style="color:#2b91af; font-size:small <span style="color:#2b91af; font-size:small SqlCommand<span style="font-size:small (<span style="color:#a31515; font-size:small <span style="color:#a31515; font-size:small "INSERT
INTO QuestionAnswer(ProblemTypeID, Question, AnswerID, Answer, NextQuestion) VALUES(@ProblemTypeID, @Question, @AnswerID, @Answer, @NextQuestion)"<span style="font-size:small , conn);
<span style="font-size:small
da.InsertCommand.Parameters.Add(

<span style="color:#a31515; font-size:small <span style="color:#a31515; font-size:small "@ProblemTypeID"<span style="font-size:small ,
<span style="color:#2b91af; font-size:small <span style="color:#2b91af; font-size:small SqlDbType<span style="font-size:small .Int).Value = textBox10.Text;
<span style="font-size:small
da.InsertCommand.Parameters.Add(

<span style="color:#a31515; font-size:small <span style="color:#a31515; font-size:small "@Question"<span style="font-size:small ,
<span style="color:#2b91af; font-size:small <span style="color:#2b91af; font-size:small SqlDbType<span style="font-size:small .NVarChar).Value = textBox4.Text;
<span style="font-size:small
da.InsertCommand.Parameters.Add(

<span style="color:#a31515; font-size:small <span style="color:#a31515; font-size:small "@AnswerID"<span style="font-size:small ,
<span style="color:#2b91af; font-size:small <span style="color:#2b91af; font-size:small SqlDbType<span style="font-size:small .Int).Value = checkBox1.Checked;
<span style="font-size:small
conn.Open();
da.InsertCommand.ExecuteNonQuery();


<span style="color:#2b91af; font-size:small <span style="color:#2b91af; font-size:small MessageBox<span style="font-size:small .Show(<span style="color:#a31515; font-size:small <span style="color:#a31515; font-size:small "Problem
Saved"<span style="font-size:small , <span style="color:#a31515; font-size:small <span style="color:#a31515; font-size:small "Saved"<span style="font-size:small ,
<span style="color:#2b91af; font-size:small <span style="color:#2b91af; font-size:small MessageBoxButtons<span style="font-size:small .OK);
<span style="font-size:small
conn.Close();


<span style="color:#2b91af; font-size:small <span style="color:#2b91af; font-size:small Form4<span style="font-size:small lfrm =
<span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small new<span style="font-size:small
<span style="color:#2b91af; font-size:small <span style="color:#2b91af; font-size:small Form4<span style="font-size:small ();
<span style="font-size:small
lfrm.Show();
}

here is my checkbox itself:

<span style="font-size:small


<span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small private<span style="font-size:small
<span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small void<span style="font-size:small checkBox1_CheckedChanged_1(<span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small object<span style="font-size:small
sender, <span style="color:#2b91af; font-size:small <span style="color:#2b91af; font-size:small EventArgs<span style="font-size:small e)
<span style="font-size:small
{
checkBox1.Checked =


<span style="color:#2b91af; font-size:small <span style="color:#2b91af; font-size:small Convert<span style="font-size:small .ToBoolean(0);
<span style="color:#008000; font-size:small <span style="color:#008000; font-size:small // False - Not checked.

<span style="color:#008000; font-size:small <span style="color:#008000; font-size:small <br/>
<span style="font-size:small
checkBox1.Checked =


<span style="color:#2b91af; font-size:small <span style="color:#2b91af; font-size:small Convert<span style="font-size:small .ToBoolean(1);
<span style="font-size:small
textBox5.Visible = checkBox1.Checked;
checkBox3.Visible = textBox5.Visible;
checkBox4.Visible = textBox5.Visible;
label14.Visible = checkBox1.Checked;


<span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small if<span style="font-size:small (checkBox2.Checked ==
<span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small true<span style="font-size:small && checkBox1.Checked ==
<span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small true<span style="font-size:small )
<span style="font-size:small
{



<span style="color:#2b91af; font-size:small <span style="color:#2b91af; font-size:small MessageBox<span style="font-size:small .Show(<span style="color:#a31515; font-size:small <span style="color:#a31515; font-size:small "Only one
checkbox can be chosen. Please try again"<span style="font-size:small );
<span style="font-size:small
}


<span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small else<span style="font-size:small
<span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small if<span style="font-size:small (checkBox2.Checked ==
<span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small true<span style="font-size:small && checkBox1.Checked ==
<span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small true<span style="font-size:small )
<span style="font-size:small
{



<span style="color:#2b91af; font-size:small <span style="color:#2b91af; font-size:small MessageBox<span style="font-size:small .Show(<span style="color:#a31515; font-size:small <span style="color:#a31515; font-size:small "Only one
checkbox can be chosen. Please try again"<span style="font-size:small );
<span style="font-size:small
}
}


please help this amateur.....


View the full article
 
Back
Top