I know in PHP it's possible to import another PHP file, so that you
don't have to type the same code over and over again. I've been trying
to find out how to do this with ASP.NET but haven't found a way. The
code I have so far is:
<%@ Page Language="VB" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.OleDb" %>
<script runat="server">

' Insert page code here
'
Sub Page_Load(sender as Object, e as EventArgs)
Dim connString as String
connString = "Provider=Microsoft.Jet.OLEDB.4.0;DATA
SOURCE=c:\phone.mdb;"

Dim objConnection as OleDbConnection
objConnection = New OleDbConnection(connString)
objConnection.Open()

Dim strSQL as String = "SELECT * FROM staff"

Dim objCommand as OleDbCommand
objCommand = New OleDbCommand(strSQL, objConnection)

Dim objDataReader as OleDbDataReader
objDataReader =
objCommand.ExecuteReader(CommandBehavior.CloseConnection)

lstNames.DataSource = objDataReader
lstNames.DataBind()

End Sub

</script>
<html>
<head>
</head>
<body>
<form runat="server">
<!-- Insert content here -->
<asp:listbox id="lstNames" runat="server"
DataValueField="FIRSTNAME" DataTextField="FIRSTNAME"
Rows="1"></asp:listbox>
</form>
</body>
</html>

I'd like to be able to chop out the code for the database connection,
so that it starts right at lstNames.DataSource
How do I go about doing this?

Re: ASP.NET import code by Nicole

Nicole
Wed Feb 02 18:28:34 CST 2005

cougar_1236@yahoo.com wrote:

> I know in PHP it's possible to import another PHP file, so that you
> don't have to type the same code over and over again. I've been trying
> to find out how to do this with ASP.NET but haven't found a way. The
> code I have so far is:
> <%@ Page Language="VB" %>
> <%@ Import Namespace="System.Data" %>
> <%@ Import Namespace="System.Data.OleDb" %>
> <script runat="server">
>
> ' Insert page code here
> '
> Sub Page_Load(sender as Object, e as EventArgs)
> Dim connString as String
> connString = "Provider=Microsoft.Jet.OLEDB.4.0;DATA
> SOURCE=c:\phone.mdb;"
>
> Dim objConnection as OleDbConnection
> objConnection = New OleDbConnection(connString)
> objConnection.Open()
>
> Dim strSQL as String = "SELECT * FROM staff"
>
> Dim objCommand as OleDbCommand
> objCommand = New OleDbCommand(strSQL, objConnection)
>
> Dim objDataReader as OleDbDataReader
> objDataReader =
> objCommand.ExecuteReader(CommandBehavior.CloseConnection)
>
> lstNames.DataSource = objDataReader
> lstNames.DataBind()
>
> End Sub
>
> </script>
> <html>
> <head>
> </head>
> <body>
> <form runat="server">
> <!-- Insert content here -->
> <asp:listbox id="lstNames" runat="server"
> DataValueField="FIRSTNAME" DataTextField="FIRSTNAME"
> Rows="1"></asp:listbox>
> </form>
> </body>
> </html>
>
> I'd like to be able to chop out the code for the database connection,
> so that it starts right at lstNames.DataSource
> How do I go about doing this?
I think of a couple of possible ways:
1. You can extend the class that represents your page and added the
functionality at the class level,
2. You can create another class to do your db work by extending one of the
db classes, and then include an instance in your code.

I hope this helps



Re: ASP.NET import code by cougar_1236

cougar_1236
Mon Feb 07 13:15:26 CST 2005

I have no idea what you're talking about. Can you please explain
further, or provide an example?

Nicole Schenk wrote:
> cougar_1236@yahoo.com wrote:
>
> > I know in PHP it's possible to import another PHP file, so that you
> > don't have to type the same code over and over again. I've been
trying
> > to find out how to do this with ASP.NET but haven't found a way.
The
> > code I have so far is:
> > <%@ Page Language="VB" %>
> > <%@ Import Namespace="System.Data" %>
> > <%@ Import Namespace="System.Data.OleDb" %>
> > <script runat="server">
> >
> > ' Insert page code here
> > '
> > Sub Page_Load(sender as Object, e as EventArgs)
> > Dim connString as String
> > connString = "Provider=Microsoft.Jet.OLEDB.4.0;DATA
> > SOURCE=c:\phone.mdb;"
> >
> > Dim objConnection as OleDbConnection
> > objConnection = New OleDbConnection(connString)
> > objConnection.Open()
> >
> > Dim strSQL as String = "SELECT * FROM staff"
> >
> > Dim objCommand as OleDbCommand
> > objCommand = New OleDbCommand(strSQL, objConnection)
> >
> > Dim objDataReader as OleDbDataReader
> > objDataReader =
> > objCommand.ExecuteReader(CommandBehavior.CloseConnection)
> >
> > lstNames.DataSource = objDataReader
> > lstNames.DataBind()
> >
> > End Sub
> >
> > </script>
> > <html>
> > <head>
> > </head>
> > <body>
> > <form runat="server">
> > <!-- Insert content here -->
> > <asp:listbox id="lstNames" runat="server"
> > DataValueField="FIRSTNAME" DataTextField="FIRSTNAME"
> > Rows="1"></asp:listbox>
> > </form>
> > </body>
> > </html>
> >
> > I'd like to be able to chop out the code for the database
connection,
> > so that it starts right at lstNames.DataSource
> > How do I go about doing this?
> I think of a couple of possible ways:
> 1. You can extend the class that represents your page and added the
> functionality at the class level,
> 2. You can create another class to do your db work by extending one
of the
> db classes, and then include an instance in your code.
>
> I hope this helps


Re: ASP.NET import code by Alvin

Alvin
Tue Feb 08 07:38:53 CST 2005

.NET's model emphasizes class reuse, not code reuse. You will need to wrap
the *offending code in a class and build an assembly from it. Then, you can
import that assembly into your application. This new assembly would be a
unit capable of being re-used over and over again.

--
Regards,
Alvin Bruney [MVP ASP.NET]

[Shameless Author plug]
The Microsoft Office Web Components Black Book with .NET
Now Available @ http://tinyurl.com/27cok
----------------------------------------------------------


<cougar_1236@yahoo.com> wrote in message
news:1107803726.275694.324450@z14g2000cwz.googlegroups.com...
>I have no idea what you're talking about. Can you please explain
> further, or provide an example?
>
> Nicole Schenk wrote:
>> cougar_1236@yahoo.com wrote:
>>
>> > I know in PHP it's possible to import another PHP file, so that you
>> > don't have to type the same code over and over again. I've been
> trying
>> > to find out how to do this with ASP.NET but haven't found a way.
> The
>> > code I have so far is:
>> > <%@ Page Language="VB" %>
>> > <%@ Import Namespace="System.Data" %>
>> > <%@ Import Namespace="System.Data.OleDb" %>
>> > <script runat="server">
>> >
>> > ' Insert page code here
>> > '
>> > Sub Page_Load(sender as Object, e as EventArgs)
>> > Dim connString as String
>> > connString = "Provider=Microsoft.Jet.OLEDB.4.0;DATA
>> > SOURCE=c:\phone.mdb;"
>> >
>> > Dim objConnection as OleDbConnection
>> > objConnection = New OleDbConnection(connString)
>> > objConnection.Open()
>> >
>> > Dim strSQL as String = "SELECT * FROM staff"
>> >
>> > Dim objCommand as OleDbCommand
>> > objCommand = New OleDbCommand(strSQL, objConnection)
>> >
>> > Dim objDataReader as OleDbDataReader
>> > objDataReader =
>> > objCommand.ExecuteReader(CommandBehavior.CloseConnection)
>> >
>> > lstNames.DataSource = objDataReader
>> > lstNames.DataBind()
>> >
>> > End Sub
>> >
>> > </script>
>> > <html>
>> > <head>
>> > </head>
>> > <body>
>> > <form runat="server">
>> > <!-- Insert content here -->
>> > <asp:listbox id="lstNames" runat="server"
>> > DataValueField="FIRSTNAME" DataTextField="FIRSTNAME"
>> > Rows="1"></asp:listbox>
>> > </form>
>> > </body>
>> > </html>
>> >
>> > I'd like to be able to chop out the code for the database
> connection,
>> > so that it starts right at lstNames.DataSource
>> > How do I go about doing this?
>> I think of a couple of possible ways:
>> 1. You can extend the class that represents your page and added the
>> functionality at the class level,
>> 2. You can create another class to do your db work by extending one
> of the
>> db classes, and then include an instance in your code.
>>
>> I hope this helps
>



Re: ASP.NET import code by cougar_1236

cougar_1236
Fri Feb 11 13:22:04 CST 2005

Still have no idea what you're talking about. I know what the classes
are, but I have to idea how to put the code I have in a class and then
import that class and use it. I've tried everything I can think of.


Alvin Bruney [MVP] wrote:
> .NET's model emphasizes class reuse, not code reuse. You will need to
wrap
> the *offending code in a class and build an assembly from it. Then,
you can
> import that assembly into your application. This new assembly would
be a
> unit capable of being re-used over and over again.
>
> --
> Regards,
> Alvin Bruney [MVP ASP.NET]
>
> [Shameless Author plug]
> The Microsoft Office Web Components Black Book with .NET
> Now Available @ http://tinyurl.com/27cok
> ----------------------------------------------------------
>
>
> <cougar_1236@yahoo.com> wrote in message
> news:1107803726.275694.324450@z14g2000cwz.googlegroups.com...
> >I have no idea what you're talking about. Can you please explain
> > further, or provide an example?
> >
> > Nicole Schenk wrote:
> >> cougar_1236@yahoo.com wrote:
> >>
> >> > I know in PHP it's possible to import another PHP file, so that
you
> >> > don't have to type the same code over and over again. I've been
> > trying
> >> > to find out how to do this with ASP.NET but haven't found a way.
> > The
> >> > code I have so far is:
> >> > <%@ Page Language="VB" %>
> >> > <%@ Import Namespace="System.Data" %>
> >> > <%@ Import Namespace="System.Data.OleDb" %>
> >> > <script runat="server">
> >> >
> >> > ' Insert page code here
> >> > '
> >> > Sub Page_Load(sender as Object, e as EventArgs)
> >> > Dim connString as String
> >> > connString = "Provider=Microsoft.Jet.OLEDB.4.0;DATA
> >> > SOURCE=c:\phone.mdb;"
> >> >
> >> > Dim objConnection as OleDbConnection
> >> > objConnection = New OleDbConnection(connString)
> >> > objConnection.Open()
> >> >
> >> > Dim strSQL as String = "SELECT * FROM staff"
> >> >
> >> > Dim objCommand as OleDbCommand
> >> > objCommand = New OleDbCommand(strSQL, objConnection)
> >> >
> >> > Dim objDataReader as OleDbDataReader
> >> > objDataReader =
> >> > objCommand.ExecuteReader(CommandBehavior.CloseConnection)
> >> >
> >> > lstNames.DataSource = objDataReader
> >> > lstNames.DataBind()
> >> >
> >> > End Sub
> >> >
> >> > </script>
> >> > <html>
> >> > <head>
> >> > </head>
> >> > <body>
> >> > <form runat="server">
> >> > <!-- Insert content here -->
> >> > <asp:listbox id="lstNames" runat="server"
> >> > DataValueField="FIRSTNAME" DataTextField="FIRSTNAME"
> >> > Rows="1"></asp:listbox>
> >> > </form>
> >> > </body>
> >> > </html>
> >> >
> >> > I'd like to be able to chop out the code for the database
> > connection,
> >> > so that it starts right at lstNames.DataSource
> >> > How do I go about doing this?
> >> I think of a couple of possible ways:
> >> 1. You can extend the class that represents your page and added
the
> >> functionality at the class level,
> >> 2. You can create another class to do your db work by extending
one
> > of the
> >> db classes, and then include an instance in your code.
> >>
> >> I hope this helps
> >


Re: ASP.NET import code by Alvin

Alvin
Fri Feb 11 13:46:53 CST 2005

The exact functionality you are after is not supported in .NET.


--
Regards,
Alvin Bruney [MVP ASP.NET]

[Shameless Author plug]
The Microsoft Office Web Components Black Book with .NET
Now Available @ http://www.lulu.com/owc
----------------------------------------------------------


<cougar_1236@yahoo.com> wrote in message
news:1108149724.785136.262210@f14g2000cwb.googlegroups.com...
> Still have no idea what you're talking about. I know what the classes
> are, but I have to idea how to put the code I have in a class and then
> import that class and use it. I've tried everything I can think of.
>
>
> Alvin Bruney [MVP] wrote:
>> .NET's model emphasizes class reuse, not code reuse. You will need to
> wrap
>> the *offending code in a class and build an assembly from it. Then,
> you can
>> import that assembly into your application. This new assembly would
> be a
>> unit capable of being re-used over and over again.
>>
>> --
>> Regards,
>> Alvin Bruney [MVP ASP.NET]
>>
>> [Shameless Author plug]
>> The Microsoft Office Web Components Black Book with .NET
>> Now Available @ http://tinyurl.com/27cok
>> ----------------------------------------------------------
>>
>>
>> <cougar_1236@yahoo.com> wrote in message
>> news:1107803726.275694.324450@z14g2000cwz.googlegroups.com...
>> >I have no idea what you're talking about. Can you please explain
>> > further, or provide an example?
>> >
>> > Nicole Schenk wrote:
>> >> cougar_1236@yahoo.com wrote:
>> >>
>> >> > I know in PHP it's possible to import another PHP file, so that
> you
>> >> > don't have to type the same code over and over again. I've been
>> > trying
>> >> > to find out how to do this with ASP.NET but haven't found a way.
>> > The
>> >> > code I have so far is:
>> >> > <%@ Page Language="VB" %>
>> >> > <%@ Import Namespace="System.Data" %>
>> >> > <%@ Import Namespace="System.Data.OleDb" %>
>> >> > <script runat="server">
>> >> >
>> >> > ' Insert page code here
>> >> > '
>> >> > Sub Page_Load(sender as Object, e as EventArgs)
>> >> > Dim connString as String
>> >> > connString = "Provider=Microsoft.Jet.OLEDB.4.0;DATA
>> >> > SOURCE=c:\phone.mdb;"
>> >> >
>> >> > Dim objConnection as OleDbConnection
>> >> > objConnection = New OleDbConnection(connString)
>> >> > objConnection.Open()
>> >> >
>> >> > Dim strSQL as String = "SELECT * FROM staff"
>> >> >
>> >> > Dim objCommand as OleDbCommand
>> >> > objCommand = New OleDbCommand(strSQL, objConnection)
>> >> >
>> >> > Dim objDataReader as OleDbDataReader
>> >> > objDataReader =
>> >> > objCommand.ExecuteReader(CommandBehavior.CloseConnection)
>> >> >
>> >> > lstNames.DataSource = objDataReader
>> >> > lstNames.DataBind()
>> >> >
>> >> > End Sub
>> >> >
>> >> > </script>
>> >> > <html>
>> >> > <head>
>> >> > </head>
>> >> > <body>
>> >> > <form runat="server">
>> >> > <!-- Insert content here -->
>> >> > <asp:listbox id="lstNames" runat="server"
>> >> > DataValueField="FIRSTNAME" DataTextField="FIRSTNAME"
>> >> > Rows="1"></asp:listbox>
>> >> > </form>
>> >> > </body>
>> >> > </html>
>> >> >
>> >> > I'd like to be able to chop out the code for the database
>> > connection,
>> >> > so that it starts right at lstNames.DataSource
>> >> > How do I go about doing this?
>> >> I think of a couple of possible ways:
>> >> 1. You can extend the class that represents your page and added
> the
>> >> functionality at the class level,
>> >> 2. You can create another class to do your db work by extending
> one
>> > of the
>> >> db classes, and then include an instance in your code.
>> >>
>> >> I hope this helps
>> >
>