|
-
Dec 13th, 2002, 01:13 PM
#1
Thread Starter
Hyperactive Member
Simple Databas app HELP!
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!
-
Dec 13th, 2002, 01:19 PM
#2
Addicted Member
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.
-
Dec 13th, 2002, 01:20 PM
#3
Thread Starter
Hyperactive Member
would it just be easier in vb 6? if so where is a sample
-
Dec 13th, 2002, 01:44 PM
#4
Hyperactive Member
start a new windows app, drag and drop a datagrid onto the form, then add the following code:
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
...and then change the path to the MSAccess file you want to use.
-
Dec 13th, 2002, 03:47 PM
#5
Thread Starter
Hyperactive Member
how can i update it with the changes made?
-
Dec 13th, 2002, 03:54 PM
#6
Hyperactive Member
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?
-
Dec 13th, 2002, 03:57 PM
#7
Thread Starter
Hyperactive Member
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.
-
Dec 13th, 2002, 03:58 PM
#8
Thread Starter
Hyperactive Member
yes the user my add/remove/edit things.
this works fine but when you load it again it dosnt update!
-
Dec 14th, 2002, 10:26 AM
#9
Thread Starter
Hyperactive Member
-
Dec 14th, 2002, 11:30 AM
#10
Hyperactive Member
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
-
Dec 14th, 2002, 01:35 PM
#11
Sleep mode
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|