PC Review


Reply
Thread Tools Rate Thread

ASP.NET import code

 
 
cougar_1236@yahoo.com
Guest
Posts: n/a
 
      25th Jan 2005
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?

 
Reply With Quote
 
 
 
 
=?Utf-8?B?Q293Ym95IChHcmVnb3J5IEEuIEJlYW1lcikgLSBN
Guest
Posts: n/a
 
      26th Jan 2005
Create additional classes. For data, downloading the Microsoft Data Access
Application block is a good start. You can then create business classes that
use the block to return data to pages.

If you want to merely pass through, make the methods in the class static
(Shared keyword in Visual Basic).


---

Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

***************************
Think Outside the Box!
***************************

"(E-Mail Removed)" 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?
>
>

 
Reply With Quote
 
cougar_1236@yahoo.com
Guest
Posts: n/a
 
      26th Jan 2005
I tried using classes, but it doesn't seem to allow me to do what I
want to do. Can you show me an example of how to create a class with
the code I have there? All I want is to import the database commands,
but when I try to import my class it doesn't recognize any of the
variables that were declared. I tried instantiating it as an object but
that didn't work either.

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Import XML from web through code Jared Microsoft Access External Data 0 8th May 2010 04:12 AM
Import code help jln via OfficeKB.com Microsoft Excel Programming 1 6th Nov 2006 07:53 PM
Import VBA Code in Excel-File ? (Export VBA Code to file) Matthias Pospiech Microsoft Excel Programming 2 22nd Mar 2005 04:56 PM
ASP.NET import code cougar_1236@yahoo.com Microsoft Dot NET Framework 5 11th Feb 2005 07:46 PM
Import VBA Code Joe Zamboni Microsoft Excel Programming 2 10th Jul 2003 07:39 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:33 AM.