Skip to content

How to insert bit type value in database?

Faisal Ansari

Asked Jan 29, 2012, 10:45 PM EST3 answers
Share
LinkedInX
hello guys how r u ?

my question is that, i am trying this code...

PowerShell
using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using DataSet1TableAdapters;


public partial class _Default : System.Web.UI.Page
{
    UsersTableAdapter insertUser;
    protected void Page_Load(object sender, EventArgs e)
    {


    }
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        insertUser = new UsersTableAdapter();
        insertUser.Insert(txtUserName.Text, txtPassword.Text, txtSuperPassword.Text, ddlActive.SelectedItem.Text, Convert.ToBoolean(ddlActive.SelectedValue.ToString()));
        Response.Write("inserted...");
    }
}

but data is not being insert into database 

what is the problem  kindly guide me ...


Reply Soon

Thanks

3 Answers

Know the answer? Post it. Somebody with the same question will find it here.

  • Suthish Nair
    +1
     Assuming ddlActive.SelectedValue having values as 0 or 1, then

     SqlCommand sqlcmd;
     sqlcmd.Parameters.AddWithValue("@Active", SqlDbType.Bit).Value = Convert.ToInt16(ddlActive.SelectedValue);

    or,

     sqlcmd.Parameters.AddWithValue("@Active", SqlDbType.Bit).Value = ddlActive.SelectedValue == "true" ? 1 : 0;

    Then do insertion...
    +1
  • 0
    thanks 4 reply suthish  and your answer works :)
     
    but i wanna know that bit data type does not work on dataset xsd  which i am using ?
    0
  • 0
    thanks 4 reply suthish  and your answer works :)
     
    but i wanna know that bit data type does not work on dataset xsd  which i am using ?
    0