Windows Develop Bookmark and Share   
 index > Windows Forms Data Controls and Databinding > ADO.NET and MS access file
 

ADO.NET and MS access file

I am fairly new to Visual basic programming and have a form with the datagridview control on it.  I would like to know how to set this up with code and call my .MDB file into it, using ADO.NET OLEDB Jet 4.0, also what refernces do I need to add using Visual basic 2008 express.
Look forward to your help with some snippetts if possible.
  • Moved byVMazurMVP, ModeratorMonday, October 05, 2009 10:22 AM (From:ADO.NET Data Providers)
  • Moved byAland LiMSFT2 hours 33 minutes agoIncorrect forum. (From:Windows Forms Data Controls and Databinding)
  •  
Storm1  Saturday, October 03, 2009 11:49 PM
Hi Storm,

Here is a sample for your reference,

Imports System.Data.OleDb

Public Class Form1

    Dim myDA As OleDbDataAdapter

    Dim myDataSet As DataSet

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        Dim con As OleDbConnection = New OleDbConnection("Provider=Microsoft.jet.oledb.4.0;data source=|DataDirectory|\myDB.mdb")

        Dim cmd As OleDbCommand = New OleDbCommand("SELECT * FROM Table1", con)

        con.Open()

        myDA = New OleDbDataAdapter(cmd)

        'Here one CommandBuilder object is required.

        'It will automatically generate DeleteCommand,UpdateCommand and InsertCommand for DataAdapter object  

        Dim builder As OleDbCommandBuilder = New OleDbCommandBuilder(myDA)

        myDataSet = New DataSet()

        myDA.Fill(myDataSet, "MyTable")

        DataGridView1.DataSource = myDataSet.Tables("MyTable").DefaultView

        con.Close()

        con = Nothing

    End Sub

 

    ' Save data back into database  

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        Me.Validate()

        Me.myDA.Update(Me.myDataSet.Tables("MyTable"))

        Me.myDataSet.AcceptChanges()

    End Sub

End Class


Does this work for you? If you have any questions or concerns, please update the thread and we will have a further discussion.

 

 

Best Regards

Yichun Feng



Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
Yichun_Feng  Monday, October 05, 2009 4:01 AM
Hi Storm,

Here is a sample for your reference,

Imports System.Data.OleDb

Public Class Form1

    Dim myDA As OleDbDataAdapter

    Dim myDataSet As DataSet

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        Dim con As OleDbConnection = New OleDbConnection("Provider=Microsoft.jet.oledb.4.0;data source=|DataDirectory|\myDB.mdb")

        Dim cmd As OleDbCommand = New OleDbCommand("SELECT * FROM Table1", con)

        con.Open()

        myDA = New OleDbDataAdapter(cmd)

        'Here one CommandBuilder object is required.

        'It will automatically generate DeleteCommand,UpdateCommand and InsertCommand for DataAdapter object  

        Dim builder As OleDbCommandBuilder = New OleDbCommandBuilder(myDA)

        myDataSet = New DataSet()

        myDA.Fill(myDataSet, "MyTable")

        DataGridView1.DataSource = myDataSet.Tables("MyTable").DefaultView

        con.Close()

        con = Nothing

    End Sub

 

    ' Save data back into database  

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        Me.Validate()

        Me.myDA.Update(Me.myDataSet.Tables("MyTable"))

        Me.myDataSet.AcceptChanges()

    End Sub

End Class


Does this work for you? If you have any questions or concerns, please update the thread and we will have a further discussion.

 

 

Best Regards

Yichun Feng



Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
Yichun_Feng  Monday, October 05, 2009 4:01 AM
Hi,

I have moved this thread back, since I think it is mostly related to ADO.

Regards,
Aland Li
Please mark the replies as answers if they help and unmark if they don't. This can be beneficial to other community members reading the thread.
Aland Li  2 hours 33 minutes ago
Hi,

I have moved this thread back, since I think it is mostly related to ADO.

Regards,
Aland Li
Please mark the replies as answers if they help and unmark if they don't. This can be beneficial to other community members reading the thread.

I quite agree with you~
Wenn ich dich hab?gibt es nichts, was unerträglich ist.坚持不懈?/font>http://hi.baidu.com/1987raymond
1987raymond  2 hours 17 minutes ago

You can use google to search for other answers

Custom Search

More Threads

• Strongly typed DataSet that isn't connected to a data source.
• IErrorInfo.GetDescription failed with E_FAIL(0x80004005)
• DataGrid_KeyDown event
• Refresh DataSet from SQL Server 2005
• How to save the single quoted data to the databse? VB.net or VS 2005(vb)
• bindingNavigatorMoveNext buttons are skipping over records in bound table.
• Datagridview Performance "Work around"
• HOW TO AVOID ENTERING READONLY CELLS ON A DATAGRIDVIEW
• Refresh DataBinding
• DataGridView UserDeletedRow event does not always fire