Solved

How do I fix "sqlconnection is undefined"?

Posted on 2010-09-14
2
527 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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 In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

821 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