View data from a data adapter

paulthepaddy

Well-known member
Joined
Apr 9, 2011
Messages
222
Location
UK
Programming Experience
Beginner
hey guys took me a while figuring this out but finally got a web service half going, i can access a database on the server side but i cant quite figurre out how ot read it on client side.

Server Side
VB.NET:
Public Class Image
    Inherits System.Web.Services.WebService

    <WebMethod()> _
    Public Function GetRecords()
        Dim con As New OleDb.OleDbConnection
        con.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\invoices.accdb"
        Dim ds As New DataSet
        Dim da As OleDb.OleDbDataAdapter
        con.Open()
        da = New OleDb.OleDbDataAdapter("SELECT * FROM Invoices", con)
        da.Fill(ds, "Invoices")
        con.Close()
        Return da
    End Function
    <WebMethod()> _
    Public Sub NewRecord(Invoice_Name As String, customer_Name As String, Total_Total As Integer)
        Dim con As New OleDb.OleDbConnection
        con.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\invoices.accdb"
        Dim ds As New DataSet
        Dim da As OleDb.OleDbDataAdapter
        con.Open()
        da = New OleDb.OleDbDataAdapter("SELECT * FROM Invoices", con)
        da.Fill(ds, "Invoices")
        Dim cb As New OleDb.OleDbCommandBuilder(da)
        cb.QuotePrefix = "["
        cb.QuoteSuffix = "]"
        Dim dsNewRow As DataRow
        dsNewRow = ds.Tables("Invoices").NewRow()
        dsNewRow.Item("Invoice Number") = Invoice_Name
        dsNewRow.Item("Date") = Format(System.DateTime.Today, "dd/MM/yy")
        dsNewRow.Item("Customer") = customer_Name
        dsNewRow.Item("Amount") = Total_Total
        dsNewRow.Item("Paid") = False
        ds.Tables("Invoices").Rows.Add(dsNewRow)
        da.Update(ds, "Invoices")
        con.Close()
    End Sub

so far i have played around with this bit of code adding and taking bits in and out, but i just cant figure it out

VB.NET:
Dim ws As New localhost.Service1
        Dim da As OleDb.OleDbDataAdapter = New OleDb.OleDbDataAdapter()
        Dim ds As DataSet

        da = ws.GetRecords
        Me.InvoicesTableAdapter.Fill(da)

if anyone can tell me how to display the data onto a datagrid after sending the data adapter back to the client, it would help alot
 
Your web service doesn't return the data adapter. You use the adapter in the web service to populate a DataTable and return that, or else populate instances of your own DTO class and return a collection of those. The adapter is for data access and the data access occurs inside the web service.

Also, don't ever declare a function without a return type. You should turn Option Strict On so the compiler won't let you.
 
thanks jmchilhinney, u always answer loads of my quests :D

is their an easier way to pass all the data from a database on the server to the datagrid in my client, all the editing and searching happen's on the client.

sorry it took so long getting back to you, been quite busy working as well as finding time for a child and programming lol
PS i changed option strick on, thanks for infomation
 
Back
Top