Because of my background, I prefer using SQL. Here are a few examples using SQL. They are a good staring point.
=====================================================================
=====================================================================
Delete a record using SQL
=====================================================================
'--------------------------------------------------------------------
' Delete using SQL
'--------------------------------------------------------------------
Dim conn = New System.Data.OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=firstdb.accdb")
Dim cmd As New System.Data.OleDb.OleDbCommand
cmd.CommandType = System.Data.CommandType.Text
cmd.CommandText = "DELETE PD WHERE MSG = 15"
cmd.Connection = conn
conn.Open()
cmd.ExecuteNonQuery()
conn.Close()
'--------------------------------------------------------------------
' Use this to refresh the datagrid and reflex the changes
'--------------------------------------------------------------------
Me.PDTableAdapter.Fill(Me.FirstdbDataSet.PD)
=====================================================================
To me, this is a lot cleaner than using the ADOX method
=====================================================================
'--------------------------------------------------------------------
' Create table using SQL
'--------------------------------------------------------------------
Dim conn = New System.Data.OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=firstdb.accdb")
Dim cmd As New System.Data.OleDb.OleDbCommand
cmd.CommandType = System.Data.CommandType.Text
cmd.CommandText = ""
cmd.CommandText = cmd.CommandText & "CREATE TABLE CREATE_TEST1"
cmd.CommandText = cmd.CommandText & " ("
cmd.CommandText = cmd.CommandText & " FIELD1 CHAR"
cmd.CommandText = cmd.CommandText & " );"
cmd.Connection = conn
conn.Open()
cmd.ExecuteNonQuery()
conn.Close()
Obviously using the "delete" example, you can change commands and insert, etc records
=====================================================================
=====================================================================
Delete a record using SQL
=====================================================================
'--------------------------------------------------------------------
' Delete using SQL
'--------------------------------------------------------------------
Dim conn = New System.Data.OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=firstdb.accdb")
Dim cmd As New System.Data.OleDb.OleDbCommand
cmd.CommandType = System.Data.CommandType.Text
cmd.CommandText = "DELETE PD WHERE MSG = 15"
cmd.Connection = conn
conn.Open()
cmd.ExecuteNonQuery()
conn.Close()
'--------------------------------------------------------------------
' Use this to refresh the datagrid and reflex the changes
'--------------------------------------------------------------------
Me.PDTableAdapter.Fill(Me.FirstdbDataSet.PD)
=====================================================================
To me, this is a lot cleaner than using the ADOX method
=====================================================================
'--------------------------------------------------------------------
' Create table using SQL
'--------------------------------------------------------------------
Dim conn = New System.Data.OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=firstdb.accdb")
Dim cmd As New System.Data.OleDb.OleDbCommand
cmd.CommandType = System.Data.CommandType.Text
cmd.CommandText = ""
cmd.CommandText = cmd.CommandText & "CREATE TABLE CREATE_TEST1"
cmd.CommandText = cmd.CommandText & " ("
cmd.CommandText = cmd.CommandText & " FIELD1 CHAR"
cmd.CommandText = cmd.CommandText & " );"
cmd.Connection = conn
conn.Open()
cmd.ExecuteNonQuery()
conn.Close()
Obviously using the "delete" example, you can change commands and insert, etc records