|
-
Feb 27th, 2008, 07:32 AM
#1
Thread Starter
Hyperactive Member
[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
-
Feb 27th, 2008, 08:00 AM
#2
Fanatic Member
Re: [2005] Comparing data types
Using this query you can information about columns in your database
vb Code:
query = "SELECT *
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME = 'MyTable'"
-
Feb 27th, 2008, 08:46 AM
#3
Thread Starter
Hyperactive Member
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
-
Feb 27th, 2008, 08:53 AM
#4
Fanatic Member
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.
-
Feb 27th, 2008, 09:54 AM
#5
Thread Starter
Hyperactive Member
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.
-
Feb 27th, 2008, 09:55 AM
#6
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 ...
-
Feb 27th, 2008, 10:15 AM
#7
Fanatic Member
Re: [2005] Comparing data types
you can use an if structure and
vb Code:
if typeof DataGridView1.Columns(e.ColumnIndex).ValueType is System.boolean then
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|