Results 1 to 7 of 7

Thread: [2005] Comparing data types

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2004
    Posts
    262

    [2005] Comparing data types

    Hi All,

    Hoping you can help. The below if statement works but it feels wrong to me

    Code:
    Dim upsql As String = "Update Calls SET " & col & " = @newvalue Where callID = @callid"
            Dim sqlcmd As New SqlCommand(upsql, sqlcon)
    
            If DataGridView1.Columns(e.ColumnIndex).ValueType.ToString = "System.Boolean" Then
                sqlcmd.Parameters.Add("@newvalue", SqlDbType.Bit)
            Else
                sqlcmd.Parameters.Add("@newvalue", SqlDbType.Text)
            End If

    Does anyone know a better way to find out if my datacolumn is a boolean or not.

    Cheers

  2. #2
    Fanatic Member
    Join Date
    Feb 2007
    Location
    Eindhoven
    Posts
    828

    Re: [2005] Comparing data types

    Using this query you can information about columns in your database

    vb Code:
    1. query = "SELECT *
    2. FROM INFORMATION_SCHEMA.COLUMNS
    3. WHERE TABLE_NAME = 'MyTable'"

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2004
    Posts
    262

    Re: [2005] Comparing data types

    Thanks, not quite what I need though.
    I just need to know how i run an if statement or a case statement on the below.
    Code:
    DataGridView1.Columns(e.ColumnIndex).ValueType
    eg

    Code:
    Select case DataGridView1.Columns(e.ColumnIndex).ValueType
    case boolean 
    'blah blah
    
    case text
    'blah blah
    
    case int
    'blah blah
    
    Case else

  4. #4
    Fanatic Member
    Join Date
    Feb 2007
    Location
    Eindhoven
    Posts
    828

    Re: [2005] Comparing data types

    Well i think you already got your solution. The case you just did would be the best solution for this problem. You have the type of the column you ar looking for and you know the different possibilities. Either it is an if statement or a case as you just did.

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2004
    Posts
    262

    Re: [2005] Comparing data types

    Thanks for your time on this, my problem is that it will not let you do a comparison like this

    If boolean = boolean then

    end if

    As you get an error saying boolean is a type and cannot be used in an expression.

    So how do you do a comparison on datatypes.

  6. #6
    Frenzied Member
    Join Date
    May 2006
    Location
    Toronto, ON
    Posts
    1,093

    Re: [2005] Comparing data types

    You can't use = to find a datatype, you have to use Is.

    So, it would be:

    If bVariable Is Boolean then ...

  7. #7
    Fanatic Member
    Join Date
    Feb 2007
    Location
    Eindhoven
    Posts
    828

    Re: [2005] Comparing data types

    you can use an if structure and

    vb Code:
    1. if typeof DataGridView1.Columns(e.ColumnIndex).ValueType is System.boolean then
    2.  
    3. end if

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width