Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

What's the VB.NET EQUIVALENT CODE for this VB6 code?

Posted on 2005-03-28
3
Medium Priority
?
243 Views
Last Modified: 2012-05-05
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;Password=ThePassword;Persist Security Info=True;User ID=TheUser;initial Catalog=TheDatabaseName;Data 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("FirstName")
Wend
RS1.Close
Set RS1=Nothing
Con1=Close
Set Con1=Nothing
0
Comment
Question by:Anadaboy
  • 2
3 Comments
 
LVL 52

Expert Comment

by:Carl Tawn
ID: 13643978
       Dim oConn As New SqlClient.SqlConnection("Password=ThePassword;Persist Security Info=True;User ID=TheUser;Initial Catalog=TheDataBaseName;Data Source=111.111.111.111")
        oConn.Open()

        Dim oCmd As New SqlClient.SqlCommand("SELECT * FROM EmployeeMaster WHERE LastName='Smith'")
        Dim oRS As SqlClient.SqlDataReader = oCmd.ExecuteReader(CommandBehavior.CloseConnection)

        While (oRS.Read())
            Label1.Text = oRS("FirstName")
        End While

        oRS.Close()
        oConn.Close()
0
 

Author Comment

by:Anadaboy
ID: 13644098
I tried what was provided from Carl Tawn and got this error:  

An unhandled exception of type 'System.InvalidOperationException' occurred in system.data.dll

Additional information: ExecuteReader: Connection property has not been initialized.

What am I missing?
0
 
LVL 52

Accepted Solution

by:
Carl Tawn earned 2000 total points
ID: 13644189
Ooops, sorry, missed a bit.

Change this line:

   Dim oCmd As New SqlClient.SqlCommand("SELECT * FROM EmployeeMaster WHERE LastName='Smith'")

To:

    Dim oCmd As New SqlClient.SqlCommand("SELECT * FROM EmployeeMaster WHERE LastName='Smith'", oConn)
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
Integration Management Part 2
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses

571 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question