PDA

View Full Version : Importing data from Access Database


dmiranda
04-13-04, 02:07 PM
Using database "mydb.mdb" (which has one field with three records) , how do I import data from that to a label on my ASP form?

For instance the database looks like this:

myfield
------
record1
record2
record3

When I open up my page, I would like the label to automatically show the first record on the database, that is, 'record1'

How do I do this?

Thanks in advance

wessamzeidan
04-20-04, 02:07 PM
Dim cn As new OledbConnection("yourconnectiontring")
Dim qry As String="select * from yourtable"
Dim cm as New OledbCommand(qry,cn)
Dim dr as OledbDataReader

cn.Open()
dr=cm.ExecuteReader()
If dr.Read
label1.Text=dr.Item(0)
End If
dr.Close()
cn.Close()