Results 1 to 2 of 2

Thread: Sage

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2010
    Posts
    1

    Question Sage

    I have been set the task of providing a small forms app to interact with Sage Line 50 Accounts database.

    Before I get started though I wondered if anyone knew if you can use VB to retrieve and write data to and from the database and if so how? I read somewhere that it's ODBC?

    Cheers

  2. #2
    PowerPoster cicatrix's Avatar
    Join Date
    Dec 2009
    Location
    Moscow, Russia
    Posts
    3,654

    Re: Sage

    Yes, I thnk that creating database front-ends is what VB does the best

    The classes you need are within the System.Data.Odbc or more generally System.Data (contains classes for OleDb connections, Sql server, etc)

    HEere is the sample code:

    vb.net Code:
    1. Sub ConnectToDB()
    2.         Dim conn As New Odbc.OdbcConnection("Your connection String")
    3.         Dim cmd As New Odbc.OdbcCommand("select * from tablename;", conn)
    4.  
    5.         ' now you can read your data sequentally row by row
    6.         Dim rd As Odbc.OdbcDataReader
    7.         ' OR with a data adapter
    8.         Dim ap As New Odbc.OdbcDataAdapter("select * from tablename;", conn)
    9.  
    10.         Dim dt As New DataTable("tablename")
    11.         Try
    12.             ' read data with the reader:
    13.             conn.Open()
    14.  
    15.             rd = cmd.ExecuteReader
    16.             Do While rd.Read
    17.                 Dim field1 As Object = rd.Item("field1")
    18.                 Dim field2 As Object = rd.Item("field2")
    19.                 ' etc
    20.             Loop
    21.  
    22.             conn.Close()
    23.  
    24.             ' Or read with the adapter
    25.  
    26.             conn.Open()
    27.             ap.Fill(dt) ' Fill the datatable with values
    28.             ' You can now assign your datatable as a datasource to some control
    29.             conn.Close()
    30.         Catch ex As Exception
    31.             ' Something terrible has happenned - tell user.
    32.         End Try
    33.     End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width