Anadaboy
asked on
What's the VB.NET EQUIVALENT CODE for this VB6 code?
The following is some VB 6.0 code. I need the equivalent code in VB.NET to accomplish the SAME EXACT thing IN AS FEW LINES OF CODE AS POSSIBLE.
I WILL PASTE YOUR SUPPLIED CODE DIRECTLY INTO MY VB.NET ENVIRONMENT TO TEST IT SO PLEASE MAKE SURE IT'S COMPLETE. THANKS!
Set Con1 = New ADODB.Connection
Con1.Open "Provider=SQLOLEDB.1;Passw ord=ThePas sword;Pers ist Security Info=True;User ID=TheUser;initial Catalog=TheDatabaseName;Da ta Source=111.111.111.111"
Set RS1 = New ADODB.Recordset
RS1.Source = "SELECT * FROM EmployeeMaster Where LastName= '"& Smith &"'
RS1.ActiveConnection = Con1
RS1.Open
While Not RS1.EOF
label1.caption=RS1("FirstN ame")
Wend
RS1.Close
Set RS1=Nothing
Con1=Close
Set Con1=Nothing
I WILL PASTE YOUR SUPPLIED CODE DIRECTLY INTO MY VB.NET ENVIRONMENT TO TEST IT SO PLEASE MAKE SURE IT'S COMPLETE. THANKS!
Set Con1 = New ADODB.Connection
Con1.Open "Provider=SQLOLEDB.1;Passw
Set RS1 = New ADODB.Recordset
RS1.Source = "SELECT * FROM EmployeeMaster Where LastName= '"& Smith &"'
RS1.ActiveConnection = Con1
RS1.Open
While Not RS1.EOF
label1.caption=RS1("FirstN
Wend
RS1.Close
Set RS1=Nothing
Con1=Close
Set Con1=Nothing
ASKER
I tried what was provided from Carl Tawn and got this error:
An unhandled exception of type 'System.InvalidOperationEx ception' occurred in system.data.dll
Additional information: ExecuteReader: Connection property has not been initialized.
What am I missing?
An unhandled exception of type 'System.InvalidOperationEx
Additional information: ExecuteReader: Connection property has not been initialized.
What am I missing?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
oConn.Open()
Dim oCmd As New SqlClient.SqlCommand("SELE
Dim oRS As SqlClient.SqlDataReader = oCmd.ExecuteReader(Command
While (oRS.Read())
Label1.Text = oRS("FirstName")
End While
oRS.Close()
oConn.Close()