Hey guys, I'm only 12 and am working on a project for my school.
I have a access file and want to display a table from it in my vb.net app. I just made the move to vb.net and help!
Printable View
Hey guys, I'm only 12 and am working on a project for my school.
I have a access file and want to display a table from it in my vb.net app. I just made the move to vb.net and help!
I've not tried this, but it won't hurt - drag and drop the access file into your project window. It may set up everything you need to use the access DB. If not then you're going to have to get familiar with ADO.NET.
would it just be easier in vb 6? if so where is a sample
start a new windows app, drag and drop a datagrid onto the form, then add the following code:
...and then change the path to the MSAccess file you want to use.VB Code:
Private Sub bindAuthors() Dim connString As String = "Provider=Microsoft.Jet.OLEDB.4.0;" & _ "Data Source=D:\AccessData\BIBLIO2002.mdb" Dim cn As OleDbConnection = New OleDbConnection(connString) Dim cmdText As String = "Select * From Authors" Dim cmd As OleDbCommand = New OleDbCommand(cmdText, cn) Dim ds As DataSet = New DataSet("Authors") Dim da As OleDbDataAdapter = New OleDbDataAdapter(cmd) da.Fill(ds) DataGrid1.DataSource = ds.Tables(0) End Sub Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load bindAuthors() End Sub
how can i update it with the changes made?
r u typing in the grid and wanna save the changes? r u trying out any code and it's not working or r u just lookin for a cut and paste solution?
No acualy i understand VB very well acualy and I'm lost when it comes to databases.
I must modify the code a great deal to get it to work in my app, and still if you want you can have your name in the about box.
yes the user my add/remove/edit things.
this works fine but when you load it again it dosnt update!
bUmP
here's one of a million different ways to do an update, you can fool around with this code to do the inserts and deletes:
VB Code:
Private Sub updateData() Dim connString As String = "Provider=Microsoft.Jet.OLEDB.4.0;" & _ "Data Source=D:\AccessData\BIBLIO2002.mdb" Dim cmdText As String = "Select * From Authors" Dim dt As DataTable = CType(DataGrid1.DataSource, DataTable) Dim ds As DataSet = dt.DataSet Dim cn As OleDbConnection = New OleDbConnection(connString) Dim cmd As OleDbCommand = New OleDbCommand(cmdText, cn) Dim da As OleDbDataAdapter = New OleDbDataAdapter(cmd) Dim cmdBuilder As OleDbCommandBuilder = New OleDbCommandBuilder(da) da.UpdateCommand = cmdBuilder.GetUpdateCommand() da.Update(ds) End Sub
this link should help :
http://support.microsoft.com/default...301075&SD=MSDN
Pirate:)