none
Help with connecting ms access 2007 from visual studio academic RRS feed

  • Question

  • I am new ,trying to follow the instructions in visual studio 2010 academic to connect to ms access table.I didnot find the oleDbDataAdopter on toolbox

    http://support .microsoft.com/kb/821765/EN-US/

    can someone help me with  a tutorial that is easier to follow using  visual studio academic 2010 and ms access2007? I followed another tutorial but there is no insert/update/delete.

    data/add new data source/in data source configuration wizard –database-dataset-new connection- in add connection wizard-  data source=Microsoft access  database file    in advance tab data source =     Provider=Microsoft.ACE.OLEDB.12.0  

    connection string =

    Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\testdb.accdb

    for  Generate the SQL statements

    On solution explorer -  testdbdataset.xsd   .right click on Fill,GetData() - add/ add query

    In table adapter query configuration wizard   Select * from Student

     

    DataGrid1  ; DataSource property = TestdbDataSet      instead of dataset11

    DataMember property = Student

    In the insert/delete/update button code -   I changed OleDbDataAdapter1 to StudentTableAdapter and dataset11 to TestdbDataSet

     

    [code]

    Imports System.Data.OleDb

    Public Class Form1

        Inherits System.Windows.Forms.Form

        Dim cn As OleDbConnection

        Dim cmd As OleDbCommand

        Dim dr As OleDbDataReader

        Dim icount As Integer

        Dim str As String

     

     

        'Public Class Form1

     

        Private Sub StudentBindingNavigatorSaveItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles StudentBindingNavigatorSaveItem.Click

            Me.Validate()

            Me.StudentBindingSource.EndEdit()

            Me.TableAdapterManager.UpdateAll(Me.TestdbDataSet)

     

        End Sub

     

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

            'TODO: This line of code loads data into the 'TestdbDataSet.student' table. You can move, or remove it, as needed.

            Me.StudentTableAdapter.Fill(Me.TestdbDataSet.student)

            ' OleDbDataAdapter1.Fill(DataSet11)

            StudentTableAdapter.Fill(TestdbDataSet.student)

        End Sub

     

        Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

            Dim i, rwno As Integer

            Dim colname As String

            Dim value As Object

            colname = InputBox("Enter the name of the Column to be updated")

            rwno = InputBox("Enter the Row Number to be updated: Row No starts from 0")

            value = InputBox("Enter the value to be entered into the Student table")

            Try

                'Update the column in the Student table.

                TestdbDataSet.Tables(0).Rows(rwno).Item(colname) = value

                'Update the Student table in the testdb database.

                i = StudentTableAdapter.Update(TestdbDataSet)

            Catch ex As Exception

                MessageBox.Show(ex.Message)

            End Try

            'Displays number of rows updated.

            MessageBox.Show("no of rows updated=" & i)

     

        End Sub

     

        Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click

            Dim i As Integer

            Dim rno As Integer

            rno = InputBox("Enter the Row no to be deleted: Row no starts from 0")

            Try

                'Delete a row from the Student table.

                TestdbDataSet.Tables(0).Rows(rno).Delete()

                'Update the Student table in the testdb database.

                i = StudentTableAdapter.Update(TestdbDataSet)

            Catch ex As Exception

                MsgBox(ex.Message)

            End Try

            'Displays number of rows updated.

            MessageBox.Show("no of rows updated=" & i)

     

     

        End Sub

     

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

     

            Dim i, sno As Integer

            Dim sname As String

            Dim rw As DataRow

            TestdbDataSet.Tables(0).NewRow()

            sno = InputBox("Enter the Roll no of the Student:")

            sname = InputBox("Enter the Name of the Student:")

            rw.Item("SNo") = sno

            'rw.Item("SName") = sname

            Try

                TestdbDataSet.Tables(0).Rows.Add(rw)

                'Update the Student table in the testdb database.

                i = StudentTableAdapter.Update(TestdbDataSet)

            Catch ex As Exception

                MessageBox.Show(ex.Message)

            End Try

            'Displays number of rows updated.

            MessageBox.Show("no of rows updated=" & i)

     

        End Sub

    End Class

     

    • Moved by Vicky SongMicrosoft employee Tuesday, November 9, 2010 7:15 AM (From:Visual Studio Database Development Tools (Formerly "Database Edition Forum"))
    Monday, November 8, 2010 2:45 AM

Answers

All replies