SQLConnection' is not defined

G

Guest

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.Page

Protected Sub lst_Employees_SelectedIndexChanged(ByVal sender As Object,
ByVal e As System.EventArgs) Handles lst_Employees.SelectedIndexChanged

Dim strConn As String =
"server=companyserver;database=CompanyDB;Trusted_Connection=yes"
Dim sql As String = "Select * from tbl_Master"
Dim conn As New SQLConnection(strConn)
Dim objDR As SQLDataReader
Dim Cmd As New SQLCommand(sql, conn)
conn.Open()
objDR = Cmd.ExecuteReader(System.Data.CommandBehavior.CloseConnection)

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="System.Data" %>
<%@ Import Namespace="System.Data.SQLClient" %>

thanks for any assistance.
 
D

David Wier

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

Mike Hofer

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.Page

Protected Sub lst_Employees_SelectedIndexChanged(ByVal sender As Object,
ByVal e As System.EventArgs) Handles lst_Employees.SelectedIndexChanged

Dim strConn As String =
"server=companyserver;database=CompanyDB;Trusted_Connection=yes"
Dim sql As String = "Select * from tbl_Master"
Dim conn As New SQLConnection(strConn)
Dim objDR As SQLDataReader
Dim Cmd As New SQLCommand(sql, conn)
conn.Open()
objDR = Cmd.ExecuteReader(System.Data.CommandBehavior.CloseConnection)

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="System.Data" %>
<%@ Import Namespace="System.Data.SQLClient" %>

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.SqlClient 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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,071
Latest member
MetabolicSolutionsKeto

Latest Threads

Top