Solved

How do I fix "sqlconnection is undefined"?

Posted on 2010-09-14
2
521 Views
Last Modified: 2012-05-10
I was trying to rebuild a site and got the "undefined" error on a code-behind page. I guess I was in too much of a hurry. However, I have no idea where to start to fix the error. The "myCommand" statement receives the same error.  I use visual basic. Below is the code behind.


    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim IDfromSession As String = (Session.Item("IDSession"))

        Dim myConnection As New SqlConnection("Data Source=vcnsql90.webhost4life.com;Initial Catalog=finaosms_membership;uid=************, pwd=*******************")
        myConnection.Open()

        Dim myCommand As New SqlCommand("uspGetTargetAddress", myConnection)
        myCommand.CommandType = CommandType.StoredProcedure

        myCommand.Parameters.Add("@LoginID", Data.SqlDbType.VarChar, 15)
        myCommand.Parameters("@LoginID").Value = IDfromSession

        Dim TargetAddress As String = myCommand.ExecuteScalar()

        Response.Redirect(TargetAddress, True)


        End Sub
End Class
0
Comment
Question by:bobbellows
2 Comments
 
LVL 10

Accepted Solution

by:
himanshut earned 250 total points
ID: 33679236
Are you importing the proper namespace in you class:

"Imports System.Data.SqlClient"

0
 
LVL 18

Assisted Solution

by:Ajay Sharma
Ajay Sharma earned 250 total points
ID: 33679241
In the top of page declaration, import below namespaces:
Imports System.Data
Imports System.Data.SQLClient
 
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

760 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now