create column to table programmatically

  • Thread starter Thread starter ahmeddc
  • Start date Start date
A

ahmeddc

Guest
hi

I tried to programmatically create an Access 2007 table with code and create columns inside the table. But there was a problem with me, I cannot add properties to the columns.


Required :

1- Text column : I need to add the non-repetition property. Name of the property indexed =Yes (No Duplicates)

2- Single numeric column : I want to make the default value the property default value = 0
3- Date column : I want to make column properties property format = Short Date or medium time

1606582.png


The following code adds columns without the required properties

Using conA As New OleDbConnection("provider=microsoft.ace.oledb.12.0;data source=" & Application.StartupPath & "\test.accdb;Jet OLEDB:Database Password=123456")
conA.Open()
Using cmd As New OleDbCommand()
cmd.Connection = conA
cmd.CommandText = ("CREATE TABLE sample1 ([id] COUNTER IDENTITY(1,1),[intnumb] Single ,[SessionId] VARCHAR (40), [SessionDate] DATETIME,[SessionName] LONGTEXT, CONSTRAINT PKSessions PRIMARY KEY (id))")
Try
cmd.ExecuteNonQuery()
Console.WriteLine("Table column created.")
Catch ex As Exception
Console.WriteLine(ex.Message)
End Try
End Using
conA.Close()
End Using

Continue reading...
 
Back
Top