Checked value (using a Check Box control) is True or False
There is a database table column type known as: Boolean
It stores 0 or 1 for False or True respectively.
So when you detect that the check box is checked, your insertion logic should place a: 1 in the related table column
i think you want to store checked or unchecked value of checkBox in the databse....
use bit data type in sql server....
While storing the value to the database check weather checkbox is checked or not....
string str ="";
if (CheckBox1.Checked)
{ str = "true"; }
else
{ str = "false"; }
insert into table values(str);
store this str value in to the database
Thank you!
Tanveer Ahmad
Please do not forget to mark as answer if my post help you!
apurva16
Member
21 Points
87 Posts
how to check and insert checked value in database.
Apr 05, 2012 06:28 AM|LINK
hello all devlopers,
i have a problem that i want to insert checked value in database..how can i do that?
usman400
Contributor
3503 Points
721 Posts
Re: how to check and insert checked value in database.
Apr 05, 2012 06:32 AM|LINK
Checked value (using a Check Box control) is True or False
There is a database table column type known as: Boolean
It stores 0 or 1 for False or True respectively.
So when you detect that the check box is checked, your insertion logic should place a: 1 in the related table column
Bhavik Solu...
Member
746 Points
159 Posts
Re: how to check and insert checked value in database.
Apr 05, 2012 06:37 AM|LINK
Hi usman400,
i have little correction make column bit in database so it will take 0 or 1
apurva16
Member
21 Points
87 Posts
Re: how to check and insert checked value in database.
Apr 05, 2012 06:37 AM|LINK
hi,
can u give some links or example for this.
tanveer_uos
Member
376 Points
213 Posts
Re: how to check and insert checked value in database.
Apr 05, 2012 06:52 AM|LINK
Hi,
i think you want to store checked or unchecked value of checkBox in the databse....
use bit data type in sql server....
While storing the value to the database check weather checkbox is checked or not....
string str =""; if (CheckBox1.Checked) { str = "true"; } else { str = "false"; } insert into table values(str); store this str value in to the databaseTanveer Ahmad
Please do not forget to mark as answer if my post help you!
shivanand G ...
Participant
1763 Points
534 Posts
Re: how to check and insert checked value in database.
Apr 05, 2012 06:56 AM|LINK
string conn="connections string";
string qry="type the query here";
sqlcommand cmd=new sqlcommand(qry,conn);
assign the int variable to executesalar(cmd);
u will get the no of rows affected value..
if the assigned int varivable is greater then zero the u r inserted successfully!!!!
shivanand.G.N (shivu.betta@gmail.com)
apurva16
Member
21 Points
87 Posts
Re: how to check and insert checked value in database.
Apr 05, 2012 07:08 AM|LINK
hello tanveer,
following is the code of inserting into db.noww how can i store the checked value in db.
protected void ImageButton1_Click(object sender, ImageClickEventArgs e) { SqlConnection con = new SqlConnection(strConnection); con.Open(); cmd = new SqlCommand("Insert Into UserCreation(FullName,UserName,Email,PhoneNo,RegionID,StateId,CityID,Password,SecurityQue,SecurityAns,MenuMasterID) VALUES(@FullName,@UserName,@Email,@PhoneNo,@RegionID,@StateId,@CityID,@Password,@SecurityQue,@SecurityAns,@MenuMasterID)", con); cmd.CommandType = CommandType.Text; cmd.Parameters.AddWithValue("@FullName", txtFullname.Text); cmd.Parameters.AddWithValue("@UserName", txtUserName.Text); cmd.Parameters.AddWithValue("@Email", txtEmail.Text); cmd.Parameters.AddWithValue("@PhoneNo", txtPhoneno.Text); cmd.Parameters.AddWithValue("@RegionID", DdlRegion.SelectedValue); cmd.Parameters.AddWithValue("@StateId", DdlState.SelectedValue); cmd.Parameters.AddWithValue("@CityID", DdlCity.SelectedValue); cmd.Parameters.AddWithValue("@Password", txtPassword.Text); cmd.Parameters.AddWithValue("@SecurityQue", txtSecurityquestion.Text); cmd.Parameters.AddWithValue("@SecurityAns", txtSecurityanswer.Text); cmd.ExecuteNonQuery(); con.Close(); ClientScript.RegisterStartupScript(this.GetType(), "Hello", "alert('Successfully created a user');", true); txtFullname.Text = ""; txtUserName.Text = ""; txtEmail.Text = ""; txtPhoneno.Text = ""; txtPassword.Text = ""; txtConfirmpassword.Text = ""; txtSecurityquestion.Text = ""; txtSecurityanswer.Text = ""; DdlRegion.SelectedIndex = 0; DdlState.SelectedIndex = 0; DdlCity.SelectedIndex = 0; }sravanisrav
Member
470 Points
107 Posts
Re: how to check and insert checked value in database.
Apr 05, 2012 07:13 AM|LINK
Hello Apurva,
First creste a table column with datatype bit.
For example IsActive (bit).
Code for Inserting using Stored Procedure:
pIsActive.Value = true; }StoredProcedure ado.net
Thanks & Regards
Sravani
apurva16
Member
21 Points
87 Posts
Re: how to check and insert checked value in database.
Apr 05, 2012 07:20 AM|LINK
hi,
but in new user creation i hav menumasterid foreign key and datatype int.
and i poseted insert code.what is code for insert checked item.
thanx.
sravanisrav
Member
470 Points
107 Posts
Re: how to check and insert checked value in database.
Apr 05, 2012 08:48 AM|LINK
or this may help you:
Thanks & Regards
Sravani