开发者

simple vb.net database program

Over 6 years ago I did visual basic programming. I used VB6 for an editor. I did it for a semester in college, and I didnt make a good grade. Since then I have been doing other things in life. However I was asked at work to create a web application. I am creating my application in vb.net 2003. I began desigining the interface of the web form. I have 5 forms, all of them need to connect to a database which I already have prepared. I created the database in MS Access. If I can get one of the forms to look at the datab开发者_如何学Case, I think I can get the rest of them to do it. I have tried using beginner tutorials online and I am not finding anything thats helpful. The closest tutorial I have found that could atleast give me an idea of what to do, the code doesnt work, I did everything to the 'T'. http://www.startvbdotnet.com/ado/msaccess.aspx

Is there anyone out there that can help me?


What you are looking for to access Microsoft Accesss Databases (MDB) is the Microsoft JET Client. If you are using a Visual Studio here is the VB for simple access. You can query the database file with SQL.

Outside class

   Imports System.Data.OleDb
   Imports System.Data

Inside class, to access the database

    Dim cn As OleDbConnection
    Dim db As OleDbDataAdapter
    cn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\folder\file.mdb;")
    cn.Open()
    db = New OleDbDataAdapter("select * from Table1", cn)

    Dim ds As New DataSet()
    db.Fill(ds)

    For Each row As DataRow In ds.Tables(0).Rows
        me.txtRow1.text = row("Row1")
        me.txtRow2.text = row("Row2")
        me.txtRow3.text = row("Row3")
    Next

    cn.Close()
    cn.Dispose()
    cn = Nothing

For more information go to, http://en.wikipedia.org/wiki/Microsoft_Jet_Database_Engine . Hope it helps!


A 'low barrier to entry' of using an Access DB with VB.Net would be to import the ADODB COM library. Since you've done VB6 before, you should be familiar with the "classic" ADO syntax.

I'm using it right now with a small VB.Net 2008 app and it works perfectly fine. No need to deal with data connections, adapters, fill methods, data sets, or data tables.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜