Private cn As Odbc.OdbcConnection 'this is the connection object
Private rs As ADODB.Recordset 'this is the recordset object
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim con As New OleDb.OleDbConnection
Dim dbProvider As String
Dim dbSource As String
Dim ds As New DataSet
Dim da As OleDb.OleDbDataAdapter
Dim sql As String
Dim pri As String 'defined to transfer the email address which was retrieved from sql query
dbProvider = "PROVIDER=Microsoft.Jet.OLEDB.4.0;"
dbSource = "Data Source = C:\auto_email\test.mdb"
con.ConnectionString = dbProvider & dbSource
con.Open()
sql = "Select Email_address from test where Uname = @UName "
con.Parameters.AddWithValue("@UName", uname.Text)
Dim reader As OleDbDataReader = con.ExecuteReader()
If reader.HasRows = True Then 'make sure there is data returned
Label2.Text = reader.GetString(0)
Else
MessageBox.Show("No records matched your search criteria.")
End If
End Sub