Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ADOX Table, Field Type Declaration

Status
Not open for further replies.

Mongr1l

Programmer
Mar 6, 2006
179
0
0
US
Hello.

I'm writting an VB.Net application that creates an ADOX table in an Access MDB.

The field declarations are dynamic. That is to say, the user determines what the field type should be.

The selection comes from a drop down.

my code is something like this:
Code:
Dim dr as datarow

for each dr in ds.Tables("Field_Definitions").rows
  objColumn = New ADOX.Column
  With ObjColumn
    .Name = dr.Item("Field_Name")
    .Type = dr.Item("Field_Type") 
  End With
next

Problem: I'd like to find a way to convert a string declaration of a field type into an actual enumerated field type.

I'm wondering if there is short cut to the following solution:

Code:
Dim dr as datarow

for each dr in ds.Tables("Field_Definitions").rows
  objColumn = New ADOX.Column
  With ObjColumn
    .Name = dr.Item("Field_Name")

    Select Case dr.Item("Field_Type")
       Case "adVarWChar"
           .Type = DataTypeEnum.adVarWChar
       Case "adInteger"
           .Type = DataTypeEnum.adSmallInt
       Case "adDate"
           .Type = DataTypeEnum.adDate  
    End Select 

    .Type = dr.Item("Field_Type") 

  End With
next

Thanks in advance
- mongril
 
No real shortcut just make that into a function.

Code:
public static funtion getfieldtype(byval type as string) as Datatypeenum
Select Case type
       Case "adVarWChar"
           .return DataTypeEnum.adVarWChar
       Case "adInteger"
           return DataTypeEnum.adSmallInt
       Case "adDate"
           return DataTypeEnum.adDate  
       Case Else
           return nothing
    End Select 
end function

Christiaan Baes
Belgium

"My new site" - Me
 
Thanks.

I could've sworn there was a built-in converter, but now it seems sort of silly to put this much effort into finding it when your solution is so simple.

Cheers!!

- mongril
 
Sorry but there is a simpler way

Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim k As pr
        k = [Enum].Parse(GetType(pr), "r")
        Button1.Text = k.ToString
    End Sub

    Public Enum pr
        f
        r
    End Enum

So replace the select case with this.

Code:
.type = [Enum].Parse(Gettype(DataTypeEnum),dr.Item("Field_Type")
)



Christiaan Baes
Belgium

"My new site" - Me
 
Ah! Thanks, Chrissie!

I wonder, however, if there are any performance differences between methods.

- mongril
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top