?
Solved

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

Posted on 2005-03-28
3
Medium Priority
?
238 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Want to be a Web Developer? Get Certified Today!

Enroll in the Certified Web Development Professional course package to learn HTML, Javascript, and PHP. Build a solid foundation to work toward your dream job!

Question has a verified solution.

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

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…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Suggested Courses

800 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