boolean datatype?

ssfftt

Well-known member
Joined
Oct 27, 2005
Messages
163
Programming Experience
1-3
[solved]boolean datatype?

In my MSSQL table "User" there is a column called "gender", should it be a boolean type? In my database manager datatype list, there is no boolean. I tried to set it as "tinyInt" same as the way i did in Interbase stuff.

In VB.NET, i have new user registration form which contains gender, and i put 2 radioboxes on the form "male" and "female". there is my code to add a user to database, can anyone please help me complete the code by adding the gender radiobox value?

VB.NET:
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRegister.Click
        Try
            'add new record into the database
            SqlConnectionNUR.Open()
            SqlInsertCommand1.Parameters(0).Value = txtUserName.Text
 
 ---->    SqlInsertCommand1.Parameters(1).Value = ?????????????
 
            SqlInsertCommand1.Parameters(2).Value = txtAge.Text
            SqlInsertCommand1.Parameters(3).Value = txtPassword.Text
            SqlInsertCommand1.Parameters(4).Value = txtPWQ.Text
            SqlInsertCommand1.Parameters(5).Value = txtPWA.Text
            SqlInsertCommand1.ExecuteNonQuery()
            MessageBox.Show("done!")
        Catch eUpdate As System.Exception
            System.Windows.Forms.MessageBox.Show(eUpdate.Message)
        End Try
    End Sub
 
Last edited:
booleans are bits in SQL. I wouldn't advise using it for this though. Having sex be a true or false value might confuse people. ;)

Make it a char(1) field and use M/F/N. It'll take application side validation, but it's more clear.
 
great idea, thanks! i will try it now.

anyway, how is boolean type actually implemented in .NET? if u cant be botherd, i will do some research latter on :)
 
how come this forum doesnt have many people around, is it because .NET developers are all busy doing business? I was doing Delphi project and one of the Delphi forums that i visited regularly has many many people around the world, so we communicate 24/7. Interesting.
 
by doing the way that u suggested sevenhalo, i have to change the dataset.xsd, the boolean column "gender". so what is the datatype here corresponding to char in MSSQL db?
 
instead of making a listbox, i prefer to keep the radioboxes. and i have this chunck of code for the gender:

VB.NET:
            If RBMale.Checked = True Then
                SqlInsertCommand1.Parameters(1).Value = "male"
            Else
                If RBFemale.Checked = True Then
                    SqlInsertCommand1.Parameters(1).Value = "female"
                End If

does it look ok?
 
oh no, it didnt work, saying that "Input string was not a correct format".
and at runtime, the text of radioboxes disappeared. wierd~~~
 
There's alot left out in your example. I really couldn't say either way. :(

I don't know if you have a parameter added to the command.
I don't know what the commandtext for sqlinsert is.

Also, don't forget about nueters. Sounds ridiculous, but it's not a phone call you'll want to have if it's not included.
 
lol, sevenhalo, it's not a big deal, I just want to make it work and make my brian works in for .NET :)

it works perfect with boolean type as u suggested to have bit type in db.
only problem remaining: once i have databinding done on the radiobuttons, their text (label) disappear at runtime, when i remove the databinding, it appears. Can u help figure out why? not very urgent though
 
Back
Top