codebehind and custom namespce

M

mark.irwin

Hello,

I have a namespace created for handling my database connections.

This works fine when used with an aspx page that contains the code.

When i try to create a codebehind page (seperate from my namespace) I
cant get it all to work together.


test.aspx (code)
-------------------------------------------------------------------
<%@ Import namespace="My_Stuff" %>
<%@ assembly src="conn.vb" %>

<%@ Import namespace="System.Data" %>
<%@ Import namespace="System.Data.SqlClient" %>

<script runat="server">
sub Page_Load
dim strSQL as string
dim cmdSQL As SqlCommand 'execute SQL query
dim rdrData As SqlDataReader 'holds SQL query data

strSQL = "SELECT TOP 10 * FROM [some table]"

cmdSQL = New SqlCommand (strSQL , db_connect.open)
rdrData= cmdSQL.ExecuteReader()

grd_subMas.DataSource = rdrData
grd_subMas.DataBind()

rdrData.close()
db_connect.close()

end sub
</script>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1">
<title>Untitled Document</title>
</head>
<body>
<asp:DataGrid ID="grd_subMas" runat="server" />
</body>
</html>
------------------------------------------------------------------



conn.vb (code)
-------------------------------------------------------------------
Imports System.Data
Imports System.Data.SqlClient
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Configuration

NameSpace My_Stuff
Public Class db_connect
Public Shared strConn as string =
ConfigurationSettings.AppSettings([connection key])
Public Shared MyConn as New SQLConnection(strConn)

Public Shared Function open
MyConn.Open()
return MyConn
End Function

Public Shared Function close
MyConn.close()
end function

end class
end NameSpace
-------------------------------------------------------------------


The above configuration works fine.

i would like to take the Page_Load and put it into a code-behind page.

Is there a 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
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top