Results 1 to 11 of 11

Thread: Simple Databas app HELP!

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2002
    Location
    Toronto, Ontario, Canada
    Posts
    275

    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!

  2. #2
    Addicted Member Sheppe's Avatar
    Join Date
    Sep 2002
    Location
    Kelowna, BC
    Posts
    245
    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.
    [vbcode]
    On Error Goto Hell
    [/vbcode]
    Sheppe Pharis, MCSD
    Check out http://www.vb-faq.com
    Click here for access to the free Code-Express source code and component sharing network for VB6
    Want a better way to skin your .NET applications? Click here!

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2002
    Location
    Toronto, Ontario, Canada
    Posts
    275
    would it just be easier in vb 6? if so where is a sample

  4. #4
    Hyperactive Member
    Join Date
    Aug 2002
    Location
    Fort Collins, CO
    Posts
    366
    start a new windows app, drag and drop a datagrid onto the form, then add the following code:
    VB Code:
    1. Private Sub bindAuthors()
    2.     Dim connString As String = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
    3.                                "Data Source=D:\AccessData\BIBLIO2002.mdb"
    4.     Dim cn As OleDbConnection = New OleDbConnection(connString)
    5.     Dim cmdText As String = "Select * From Authors"
    6.     Dim cmd As OleDbCommand = New OleDbCommand(cmdText, cn)
    7.     Dim ds As DataSet = New DataSet("Authors")
    8.     Dim da As OleDbDataAdapter = New OleDbDataAdapter(cmd)
    9.     da.Fill(ds)
    10.     DataGrid1.DataSource = ds.Tables(0)
    11. End Sub
    12.  
    13. Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    14.     bindAuthors()
    15. End Sub
    ...and then change the path to the MSAccess file you want to use.

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2002
    Location
    Toronto, Ontario, Canada
    Posts
    275
    how can i update it with the changes made?

  6. #6
    Hyperactive Member
    Join Date
    Aug 2002
    Location
    Fort Collins, CO
    Posts
    366
    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?

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2002
    Location
    Toronto, Ontario, Canada
    Posts
    275
    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.

  8. #8

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2002
    Location
    Toronto, Ontario, Canada
    Posts
    275
    yes the user my add/remove/edit things.

    this works fine but when you load it again it dosnt update!

  9. #9

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2002
    Location
    Toronto, Ontario, Canada
    Posts
    275
    bUmP

  10. #10
    Hyperactive Member
    Join Date
    Aug 2002
    Location
    Fort Collins, CO
    Posts
    366
    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:
    1. Private Sub updateData()
    2.     Dim connString As String = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
    3.                                "Data Source=D:\AccessData\BIBLIO2002.mdb"
    4.     Dim cmdText As String = "Select * From Authors"
    5.     Dim dt As DataTable = CType(DataGrid1.DataSource, DataTable)
    6.     Dim ds As DataSet = dt.DataSet
    7.     Dim cn As OleDbConnection = New OleDbConnection(connString)
    8.     Dim cmd As OleDbCommand = New OleDbCommand(cmdText, cn)
    9.     Dim da As OleDbDataAdapter = New OleDbDataAdapter(cmd)
    10.     Dim cmdBuilder As OleDbCommandBuilder = New OleDbCommandBuilder(da)
    11.     da.UpdateCommand = cmdBuilder.GetUpdateCommand()
    12.     da.Update(ds)
    13. End Sub

  11. #11
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width