how to read the records in Access database through ODBC

how to read the records in Access database through ODBC

Post by Liu Suji » Sat, 08 Apr 2000 04:00:00



I want to test access a database in my VC++ program. But I do not know
how to do, anyone can show me a simple example or tell me how to do?

thanks,


 
 
 

how to read the records in Access database through ODBC

Post by Paul S. Gann » Sat, 08 Apr 2000 04:00:00



>I want to test access a database in my VC++ program. But I do not know
>how to do, anyone can show me a simple example or tell me how to do?

First, from control panel set up an ODBC connection to your access
database.

Then build a database app via AppWizard using CRecordView instead of
CView (I can't remember the wizard settings, but it's under "database
support").

After that, it's a case of looking at the sample apps (I believe
ENROLL is a good one).

HTH

Paul.
-------------------------------------------
Expressed opinions are usually my own.
Especially if they're any good (of course).
-------------------------------------------

 
 
 

1. Reading records from Access database.

New to the group so wondered if anyone can help with the below :

I have an access database that stores information by week number so I
want to read into a recordset and series of array's all data between
two week numbers. The code below is what i thought would work but keep
getting type mismatch error when running.

Any help appreciated.

' Database Location and file name set in Form Load Section
'
Dim database_location As String     'Location of database files.
Dim database_name As String         'Name of database file.
Dim SQLstr As String                'Variable to hold SQL Statements.
'
Dim wkfrom As Long                  'Week No. From.
Dim wkto As Long                    'Week No. To.
Dim db As Database
Dim rs As Recordset

Private Sub cmdLoadWeeks_Click()
'Obtain Week from, Week to and validate answers.
'
wkfrom = (Val(txtWk_from))
wkto = (Val(txtWk_to))
If wkfrom < 1 Or wkfrom > 53 Then
    MsgBox ("Week Number 'from' must be between 1 and 53")
    Exit Sub
End If
If wkto < 1 Or wkto > 53 Then
    MsgBox ("Week Number 'to' must be between 1 and 53")
    Exit Sub
End If
If wkfrom > wkto Then
    MsgBox ("Week from must be equal or less than Week to")
    Exit Sub
End If
MsgBox (wkfrom & " to " & wkto)
'
'Read in all wage data for given weeks.
'
Set db = OpenDatabase(database_location & database_name)
' Set the SQL select statement
SQLstr = "SELECT tbl_wage_details.wk_num, tbl_wage_details.contract_1
& ':' & tbl_wage_details.contract_2 & ':' " & _
        "& tbl_wage_details.contract_3 & ':' &
tbl_wage_details.contract_4 & ':' & tbl_wage_details.contract_5 & ':'
" & _
        "AS list1 FROM tbl_wage_details " & _
        "WHERE (((tbl_Wage_Details.Wk_Num) Between 1 And 2));"

        MsgBox (SQLstr)

    Set rs = db.OpenRecordset(SQLstr)
    If rs.BOF = True And rs.EOF = True Then
        MsgBox ("Cannot find that gang")
        rs.Close
        db.Close
        Exit Sub
    End If

End Sub

Private Sub Form_Load()
database_location = "d:\wages_oj\"
database_name = "company_oj.mdb"
End Sub

2. Ingres and firewalls

3. add records to access table fails with back cannot update read-only database

4. SQL Server Mirroring

5. Reading MS-Access-2-Database from Delphi 1 via ODBC

6. Client/Server Application Developers Needed In Singapore

7. Read-only access to VFP-Database with ODBC ?

8. class not registerd CSSID

9. Problem in adding record in an ODBC-connected Access database

10. Reading Access 2.0 db on network w/read-only access

11. ODBC database crashing accessing progam going for an access database

12. ODBC requirig login for each record read

13. Program freezes after reading 1284 records via ADO and ODBC