Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
DataType for VarChar
Message
 
 
To
31/03/2014 17:23:37
General information
Forum:
ASP.NET
Category:
Databases
Environment versions
Environment:
VB 9.0
OS:
Windows 7
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Web
Miscellaneous
Thread ID:
01597800
Message ID:
01597807
Views:
27
BTW, I remember I was trying to answer the same question.

Take a look at this answer at StackOverflow, I think I also used it in our code.

http://stackoverflow.com/questions/459572/how-do-i-get-the-sqldbtype-of-a-column-in-a-table-using-ado-net

>>There is SqlDbType.VarChar data type, but System.String type. So, for all char data it will be System.String type.
>
>Well, this causes a problem, as when I use a database which is not bound to my data dictionary, I need to rely on what the DataTable will return. So, I need to be able to differentiate between a string and a varchar.
>
>For example, this is a method I have that I call when I need to know the data type of a column, if I do not have my data dictionary to rely on. This assumes oDataTable is already available. So, I pass the field, in this case a column formely known in SQL Server, and the property I need to get info from. So, the one that is of interest here is DataType. So, I can call the method here with "FirstName", "DataType" and this will return System.String, for example, if FirstName is a column of type Character in SQL Server. But, I need a way to differentiate that from a VarChar. This seems impossible I would assume.
>
>
>    ' Return a property of a field
>    ' expC1 Field
>    Public Function GetColumnProperty(ByVal tcField As String, ByVal tcProperty As String) As Object
>        Dim lcFieldName As String = ""
>        Dim loRow As DataRow = Nothing
>
>        ' Trim just in case
>        tcField = Trim(tcField)
>
>        ' Locate the field
>        For Each loRow In oDataTable.Rows
>            lcFieldName = loRow("ColumnName")
>
>            ' If this is the field
>            If UCase(lcFieldName) = UCase(tcField) Then
>
>                ' This is an example to get the type for the column
>                lcType = loRow("DataType")
>
>            End If
>
>        Next
>
If it's not broken, fix it until it is.


My Blog
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform