|
-
Dec 18th, 2008, 09:20 AM
#1
Thread Starter
Member
Find AutoIncrement & Primary Key fields in ADODB Recordset
Hello again, everyone. I've run into yet another issue I can't seem to overcome with any of the resources at my disposal. Is it possible to determine if a field in an MS Access (2003) table is AutoIncrement and/or a Primary Key by looking at an ADODB Recordset from that table?
I'm trying to convert data from an Access database over into MySQL. As I go through each of the tables in my Access database, if that table doesn't already exist in the MySQL database, I need to create it. I'm building a SQL command string by looping through the field names of an ADODB recordset from the Access database. During this loop, I would like to identify those fields that are setup as AutoIncrement/Primary Key fields so that I can include those in my SQL statement appropriately.
Code:
Private Sub CreateNewDestinationTable(ByRef TableName As String)
Dim X As Integer
DDBCommand = "CREATE TABLE [" & TableName & "] ("
For X = 0 To OTempRS.Fields.Count - 1
DDBCommand = DDBCommand & "[" & OTempRS.Fields(X).Name & "] "
DDBCommand = DDBCommand & "VARCHAR(" & OTempRS.Fields(X).FieldSize & ")"
' --- Here is where I would add the conditional statement to include
' --- the appropriate SQL commands to create the field as a Primary
' --- Key and/or AutoIncrement field as needed.
If X < OTempRS.Fields.Count - 1 Then
DDBCommand = DDBCommand & ", "
End If
Next X
DDBCommand = DDBCommand & ")"
End Sub
I'm sure I could probably pop up a dialog to request user intervention to identify these types of fields, but it would be nice if I didn't have to. Any ideas or suggestions would be greatly appreciated. Thanks for your time.
Last edited by G_Hosa_Phat; Dec 18th, 2008 at 12:06 PM.
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
|