Solved

How do I fix "sqlconnection is undefined"?

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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
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…
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…

803 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