mickeyshelley1
asked on
How Do I execute a DLookUp function in VB.Net
I have been using the following code in access for a number of years, now that i have moved to VB.net i need the equivalent, is there such a function?
If IsNull(DLookup("[txtname]", "Advisories", "[txtname]='" & Me![ReportedBy] & "'")) Then
Exit Sub
End If
the equvlilant of Dlookup in VB.NET is to use a SQL Query
an example would be
Dim con As New SqlConnection
Dim cmd As New SqlCommand
Errorbox.Text = ""
Try
con.ConnectionString = "Data Source=XXXXX;Initial Catalog=EAFiles;Persist Security Info=True;User ID=Login;Password=XXXXXXX"
con.Open()
cmd.Connection = con
cmd.CommandText "SELECT name, advisoroes WHERE Name = txtname"
cmd.ExecuteNonQuery()
if isnull then
exit sub
end if
Catch ex As Exception
Errorbox.Text = "Error while inserting record on table..." & ex.Message
Finally
con.Close()
End Try
endsub
Dim con As New SqlConnection
Dim cmd As New SqlCommand
Errorbox.Text = ""
Try
con.ConnectionString = "Data Source=XXXXX;Initial Catalog=EAFiles;Persist Security Info=True;User ID=Login;Password=XXXXXXX"
con.Open()
cmd.Connection = con
cmd.CommandText "SELECT name, advisoroes WHERE Name = txtname"
cmd.ExecuteNonQuery()
if isnull then
exit sub
end if
Catch ex As Exception
Errorbox.Text = "Error while inserting record on table..." & ex.Message
Finally
con.Close()
End Try
endsub
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.