Friday, October 5, 2007

How to Create a Schema.ini File Programmatically

1. Start a new project in Visual Basic 6, and save project to disk
2. Add reference to Microsoft ActiveX Data Objects 2.5 Library
3. Add button to the Form
4. Double click on button and add next code

Private Sub Command1_Click()
   Dim con As New ADODB.Connection
   Dim RS As ADODB.Recordset
   con.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
   "Data Source=" & App.Path & _
   ";Extended Properties=text;"
   con.Execute & _
   "CREATE TABLE [TEST1.CSV] " & _
   "( [Name] TEXT NULL, [MaxVolt] DOUBLE NULL)"
End Sub

6. Run project and click on a button
7. Verify that SCHEMA.INI and TEST1.CSV files were created in project folder
8. Use "DROP TABLE [TEST.CSV]" to delete TEST.CSV from SCHEMA.INI and delete TEST1.CSV file from a disk

Remarks: There is no way to update SCHEMA.INI and TEST1.CSV by using ALTER TABLE sql statement. Even if tables (files) does not contain any data, next statement "ALTER TABLE [TEST.CSV] ADD COLUMN [Name2] TEXT NULL" will raise an error "Operation not supported on a table that contains data".

No comments: