SQLConnection' is not defined

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • =?Utf-8?B?QnJldA==?=

    #1

    SQLConnection' is not defined

    Please Im getting the above error due to running code below from .aspx.vb form.
    Ive taken out some code below to simplify this question.

    Partial Class Process_Master
    Inherits System.Web.UI.P age

    Protected Sub lst_Employees_S electedIndexCha nged(ByVal sender As Object,
    ByVal e As System.EventArg s) Handles lst_Employees.S electedIndexCha nged

    Dim strConn As String =
    "server=company server;database =CompanyDB;Trus ted_Connection= yes"
    Dim sql As String = "Select * from tbl_Master"
    Dim conn As New SQLConnection(s trConn)
    Dim objDR As SQLDataReader
    Dim Cmd As New SQLCommand(sql, conn)
    conn.Open()
    objDR = Cmd.ExecuteRead er(System.Data. CommandBehavior .CloseConnectio n)

    Page.DataBind()

    End Sub
    End Class

    I know most likely its missing the namespace shown below but whereever I put
    this namespace I error out. In an original webform the code above is within
    ..aspx instead of separated out and it works. Im now separating out these
    events from .aspx and am running into this "SQL" error.

    <%@ Import Namespace="Syst em.Data" %>
    <%@ Import Namespace="Syst em.Data.SQLClie nt" %>

    thanks for any assistance.
  • David Wier

    #2
    Re: SQLConnection' is not defined

    What are you trying to populate with the code (Page.DataBind)
    You should put the Imports statements in the page, for sure -

    --
    David Wier
    MVP/ASPInsider



    "Bret" <Bret@discussio ns.microsoft.co mwrote in message
    news:D5515205-A207-4504-B102-4D37FE214A0F@mi crosoft.com...
    Please Im getting the above error due to running code below from .aspx.vb
    form.
    Ive taken out some code below to simplify this question.
    >
    Partial Class Process_Master
    Inherits System.Web.UI.P age
    >
    Protected Sub lst_Employees_S electedIndexCha nged(ByVal sender As Object,
    ByVal e As System.EventArg s) Handles lst_Employees.S electedIndexCha nged
    >
    Dim strConn As String =
    "server=company server;database =CompanyDB;Trus ted_Connection= yes"
    Dim sql As String = "Select * from tbl_Master"
    Dim conn As New SQLConnection(s trConn)
    Dim objDR As SQLDataReader
    Dim Cmd As New SQLCommand(sql, conn)
    conn.Open()
    objDR =
    Cmd.ExecuteRead er(System.Data. CommandBehavior .CloseConnectio n)
    >
    Page.DataBind()
    >
    End Sub
    End Class
    >
    I know most likely its missing the namespace shown below but whereever I
    put
    this namespace I error out. In an original webform the code above is
    within
    .aspx instead of separated out and it works. Im now separating out these
    events from .aspx and am running into this "SQL" error.
    >
    <%@ Import Namespace="Syst em.Data" %>
    <%@ Import Namespace="Syst em.Data.SQLClie nt" %>
    >
    thanks for any assistance.

    Comment

    • Mike Hofer

      #3
      Re: SQLConnection' is not defined

      On Mar 13, 5:19 pm, Bret <B...@discussio ns.microsoft.co mwrote:
      Please Im getting the above error due to running code below from .aspx.vb form.
      Ive taken out some code below to simplify this question.
      >
      Partial Class Process_Master
      Inherits System.Web.UI.P age
      >
      Protected Sub lst_Employees_S electedIndexCha nged(ByVal sender As Object,
      ByVal e As System.EventArg s) Handles lst_Employees.S electedIndexCha nged
      >
      Dim strConn As String =
      "server=company server;database =CompanyDB;Trus ted_Connection= yes"
      Dim sql As String = "Select * from tbl_Master"
      Dim conn As New SQLConnection(s trConn)
      Dim objDR As SQLDataReader
      Dim Cmd As New SQLCommand(sql, conn)
      conn.Open()
      objDR = Cmd.ExecuteRead er(System.Data. CommandBehavior .CloseConnectio n)
      >
      Page.DataBind()
      >
      End Sub
      End Class
      >
      I know most likely its missing the namespace shown below but whereever I put
      this namespace I error out. In an original webform the code above is within
      .aspx instead of separated out and it works. Im now separating out these
      events from .aspx and am running into this "SQL" error.
      >
      <%@ Import Namespace="Syst em.Data" %>
      <%@ Import Namespace="Syst em.Data.SQLClie nt" %>
      >
      thanks for any assistance.
      One thing that I have noticed, even for ASP.NET applications written
      in VB.NET, is that Namespaces and Codebehind specifiers in <%@ %tags
      are CASE-SENSITIVE. I notice that your tag for the import statement
      for the System.Data.Sql Client namespace doesn't have the appropriate
      casing (you've specfied "SQLClient" in your sample as opposed to the
      correct "SqlClient" ). You might want to fix that and verify that
      that's not the problem.

      If you're using Visual Studio, definitely consider using a code-behind
      file, since they don't have those restrictions.

      This has caused my pages to fail to compile on a number of occasions.

      Hope this helps,

      Mike

      Comment

      • david.somuah@gmail.com

        #4
        Re: SQLConnection' is not defined

        Your partial class is in a seperate code-behind .vb file correct?
        Y
        ou can just put your Import statement in the code behind file.

        See the example at this location

        http://msdn2.microsoft.com/en-us/library/7f38zh8x.aspx

        Just place your import statement at the top of the page before your
        namespace (or class) declaration

        Comment

        Working...