Not able to declare variables in custom user controls

S

stevong

Hi,

I've a custom user control:

'user1.ascx

<script language="VB" runat="server">
Public str1 as string
Dim conn as System.Data.SqlClient ' But this line hits and error.
What should I do?
</script>
Hello World

I will hit compilation error. What should be the next step? Also, how
do I use custom namespaces in a custom control?

Please advise! Thanks!
 
D

David Wier

This statement:
Dim conn as System.Data.SqlClient
is not a full statement - I'm assuming you're wanting to instantiate a
Connection - - which would be more like:

Dim connAs New
SqlConnection(ConfigurationManager.ConnectionStrings("YourconnString").ConnectionString)

Import your namespace (System.Data.SqlClient )
 
B

bruce barker

only methods are allowed in a server script block. to declare var use

<%
Public str1 as string
Dim conn as System.Data.SqlClient ' But this line hits and error.
%>

but method def are not allowed here.

-- bruce (sqlwork.com)
 
G

Guest

stevong,

You need to import the correct namespace:
<%@ Import Namespace="System.Data.SqlClient" %>

You can import custom namespaces the same way
 

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

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top