2 Replies - 666 Views - Last Post: 18 October 2013 - 12:27 PM Rate Topic: -----

#1 dsalter  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 17-October 13

ms access table data into application dataset table

Posted 17 October 2013 - 07:32 PM

Hi there, I am trying to load the contents of a table from an ms access database into a dataset table that I have added to my application. Currently I'm just loading it into a data grid view like this:
Frm_Main.DataGridView2.DataSource = DirectCast(GetUser(Txt_Username.Text), DataTable)

GetUser Function:
    Public Function GetUser(ByVal Name As String) As DataTable
        Dim query As String = "SELECT * FROM Users WHERE Username = @Name"
        Dim cnGetRecords As New OleDbConnection
        cnGetRecords.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & My.Settings.EquipmentDatabase
        Dim cmdGetRecords As New OleDbCommand()
        Dim daGetRecords As New OleDbDataAdapter()
        Dim dsGetRecords As New DataTable()
        cmdGetRecords.Parameters.Clear()
        Try
            With cmdGetRecords
                .CommandText = query
                .CommandType = CommandType.Text
                .Parameters.AddWithValue("@Username", Name)
                .Connection = cnGetRecords
            End With
            DataAccess.HandleConnection(cnGetRecords)
            Dim oBindingSource As DataTable = DataAccess.GetDataTable(cmdGetRecords)
            'now check to make sure a BindingSource was returned
            If Not oBindingSource Is Nothing Then
                'return the binding source to the calling method
                Return oBindingSource
            Else
                'no binding source was returned
                Throw New Exception("There was no BindingSource returned")
                Return Nothing
            End If
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Critical, "Error")
            Return Nothing
        Finally
            'Close the connection
            DataAccess.HandleConnection(cnGetRecords)
        End Try
    End Function


On my main form I have the dataset called 'App_DataSet' with an empty table named 'Table_Users' , how would I fill the table instead of the datagridview?

Tried this and afew other things like it:
Frm_Main.App_DataSet.Tables.Item("Table_Users") = DirectCast(GetUser(Txt_Username.Text), DataTable)

but says 'Property item is read only'

Any help would be great thanks.

Is This A Good Question/Topic? 0
  • +

Replies To: ms access table data into application dataset table

#2 astonecipher  Icon User is offline

  • D.I.C.
  • member icon

Reputation: 801
  • View blog
  • Posts: 3,502
  • Joined: 03-December 12

Re: ms access table data into application dataset table

Posted 18 October 2013 - 12:09 PM

How to: Fill a Dataset with Data
Was This Post Helpful? 0
  • +
  • -

#3 andrewsw  Icon User is online

  • It's just been revoked!
  • member icon

Reputation: 3834
  • View blog
  • Posts: 13,583
  • Joined: 12-December 12

Re: ms access table data into application dataset table

Posted 18 October 2013 - 12:27 PM

You can also fill a DataTable from an ADO Recordset:

MSDN reference

MSDN said:

The link between ActiveX Data Objects (ADO) and ADO.NET is a one-way operation in that you can copy data from ADO to the DataSet, but any updates to the data must be handled by ADO.NET.

As the quote states, this is a one-way operatiion, so whether this is suitable for your purpose or not is dependent on what will eventually happen to this DataTable and its data.

BTW Your parameter is named @Name not @Username, so you should be seeing an error.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1