S Hoa
I made a complete sample for you what should fit your problem completly
The first part is to make a minimum accessdatabase as you told, therefore
do not become affraid of that part. You can paste this in a form and need a
datagrid a textbox and a button on the form. As well do you have to set a
reference to reference to COM adox ext 2.x for dll and security (that is for
creating the testdatabase). The directory is in this case C:\test1. I hope
this helps, and expect an answer from you, that I am sure you saw this,
otherwise you know probably what I want to say.
I hope this helps?
Cor
\\\
Dim dv As DataView
Private Sub Form1_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Dim catNewDB As New ADOX.Catalog
Dim fi As New IO.FileInfo("c:\test1\db1.mdb")
If fi.Exists Then
If MessageBox.Show("Delete?", "Existing File db1.mdb", _
MessageBoxButtons.YesNo) = DialogResult.Yes Then
fi.Delete()
Else
Exit Sub
End If
End If
catNewDB.Create("Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=C:\test1\db1.mdb")
'To make tables we use Adonet
Dim conn As New
OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;" & _
" Data Source=C:\test1\db1.mdb;User Id=admin;Password=;")
Dim cmd As New OleDb.OleDbCommand("CREATE TABLE persons ( " & _
"AutoId int identity ," & _
"Name NVarchar(50)," & _
"CONSTRAINT [pk_AutoId] PRIMARY KEY (AutoId)) ", conn)
conn.Open()
Try
cmd.ExecuteNonQuery()
Catch ex As OleDb.OleDbException
MessageBox.Show(ex.Message, "OleDbException")
Exit Sub
Catch ex As Exception
MessageBox.Show(ex.Message, "GeneralException")
Exit Sub
End Try
conn.Close()
Dim da As New OleDb.OleDbDataAdapter("Select * from Persons", conn)
Dim ds As New DataSet
da.Fill(ds)
ds.Tables(0).Columns("AutoId").AutoIncrement = True
ds.Tables(0).Columns("AutoId").AutoIncrementSeed = -1
ds.Tables(0).Columns("AutoId").AutoIncrementStep = -1
dv = New DataView(ds.Tables(0))
ds.Tables(0).Rows.Add(ds.Tables(0).NewRow)
ds.Tables(0).Rows(0)("Name") = "Cor"
dv.AllowNew = False
DataGrid1.DataSource = dv
TextBox1.DataBindings.Add("Text", dv, "Name")
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
dv.AllowNew = True
dv.AddNew()
dv.AllowNew = False
End Sub
///