Add access column programmatically

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

ahmeddc

Guest
hi


I want to add a column with indexed property to ms access table programmatically.

my code

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

Dim con As New OleDb.OleDbConnection("provider=microsoft.ace.oledb.12.0;data source=" & Application.StartupPath & "\test.accdb;Jet OLEDB:Database Password=12345")
con.Open()
Dim dbSchema As DataTable = con.GetOleDbSchemaTable(OleDb.OleDbSchemaGuid.Tables, New Object() {Nothing, Nothing, "goodb", "TABLE"})
con.Close()
If dbSchema.Rows.Count > 0 Then
Else
Dim cmd As New OleDb.OleDbCommand("CREATE TABLE [" + "goodb" + "] ([ID] COUNTER NOT NULL,[Field1] varchar(50) indexed(Yes (No Duplicates)), [Field2] LongBinary, Primary Key([ID]) )", con)
con.Open()
cmd.ExecuteNonQuery()
MessageBox.Show("Table Created Successfully")
con.Close()
End If
End Sub




indexed property

1548846.png

Continue reading...
 
Back
Top