Welcome to Dream.In.Code
Getting Help is Easy!

Join 132,651 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,155 people online right now. Registration is fast and FREE... Join Now!




Retrieving data from MSAccess Table

 
Reply to this topicStart new topic

Retrieving data from MSAccess Table

anuhema
post 10 Sep, 2008 - 06:47 AM
Post #1


New D.I.C Head

*
Joined: 25 Jul, 2008
Posts: 1

CODE


Dim aid, u As String
        Dim sql, dbcomm, dbread
        dbconn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;data source=" & Server.MapPath("exp_imp.mdb")
        dbconn.Open()
        sql = "Select Top 1 audit_id from audit order by id desc"
        dbcomm = New System.Data.OleDb.OleDbCommand(sql, dbconn)
        dbread = dbcomm.ExecuteReader()
        While dbread.Read
            aid = dbread(0)
        End While

        sql = "Select * from export_import_sec1"
        dbcomm = New System.Data.OleDb.OleDbCommand(sql, dbconn)
      [color=#CC0000] dbread = dbcomm.ExecuteReader()
        While dbread.Read
          If dbread(0).audit_id=aid Then  u = dbread(0).ans_1
        End While
        label3.text = u[/color]

Hi,
Im trying to retrieve all the records in dbread.
audit_id and ans_1 are two different fields in table.
if audit_id==aid i want ans_1 to be displayed in a label.
Could anybody help me!!
Thanks in advance.. wink2.gif


User is offlineProfile CardPM

Go to the top of the page

ajwsurfer
post 2 Oct, 2008 - 11:18 AM
Post #2


D.I.C Regular

Group Icon
Joined: 24 Oct, 2006
Posts: 292



Thanked 2 times

Dream Kudos: 50
My Contributions


This is similar to the way I do it. I have added a lot of bells and whistles to my own code to get the SQL syntax and any redundant code out of the code behind pages.

CODE

    Public Function GetOleDataReader(ByVal conStr As String, ByVal qryStr As String) As OleDbDataReader
        Dim oleCon As OleDbConnection = New OleDbConnection(conStr)
        oleCon.Open()
        Dim oleDbCmd As OleDbCommand = New OleDbCommand(qryStr, oleCon)

         Return oleDbCmd.ExecuteReader()
    End Function
    
    ...
    
    Dim aid As String
    Dim u As String
    
    Dim qryStr As String = "SELECT TOP 1 audit_id FROM audit ORDER BY id desc"
    Dim conStr As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" "fileDirectory\FileName,mdb"
    
    Dim dbReader as OleDbDataReader = GetOleDataReader(conStr, qryStr)

    While dbReader.Read
       aid = dbReader(0)
    End While

    
    qryStr = "SELECT TOP 1 audit_id FROM audit ORDER BY id desc"
    dbReader = GetOleDataReader(conStr, qryStr)
    
    While dbReader.Read
      If dbReader(0).audit_id = aid Then  
        u = dbReader(0).ans_1
      End If    
    End While
    
    label3.text = u



blink.gif
User is offlineProfile CardPM

Go to the top of the page

Fast ReplyReply to this topicStart new topic
Time is now: 11/23/08 05:18AM

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month