Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

open function

Status
Not open for further replies.

hlybbi

Programmer
Mar 19, 2003
91
IS
I am an asp programer but i am going into asp.net c#
But there is a problem i do not understand and that is how can i open openXodus function in page.aspx

Page.aspx.cs
namespace Xodus_default
{
using System;
using System.Data;
using System.Data.SqlClient;
using System.Data.Common;
using System.IO;
using System.Web.Util;
using System.Web.Mail;

/// Data connection strings
public class ConnData
{
public string conn;
public static void Main()
{
ConnData myConnData = new ConnData();
myConnData.openXodus();
}
public void openXodus()
{
SqlConnection mySqlConnection = new SqlConnection("server=ServerName;database=DataName;UID=username;PWD=PassW;");
try
{
mySqlConnection.Open();
Console.WriteLine("Opened Connection to {0}", mySqlConnection.ConnectionString);
}
catch
{
Console.WriteLine("Couldn't Open Connection to {0}", mySqlConnection.ConnectionString);
}
} }

Page.aspx

<Page Language=&quot;C#&quot; Debug=&quot;true&quot; Src=&quot;data.aspx.cs >
<Import Namespace=&quot;Xodus_default&quot; >
<script language=&quot;C#&quot; runat=&quot;server&quot;>

conn = ???? mySqlConnection ?????

SqlDataAdapter myCommand = new SqlDataAdapter(&quot;select * from pages&quot;, conn);
</script>



 
It looks to me like you are still trying to use the old school spaggetti code you are used to from asp.

The recommended method is to do things in your code behind. Which you have started with your Page.aspx.cs.

Are you using Visual Studio or a different IDE? Using VS the code behind page is automatically built with the page_load event included. Within the page load event under a If Not IsPostBack block is where you'll want to load your data into the controls on the page.

If you could explain what you are trying to accomplish I'll try to explain the proper method to achieve that. That'l do donkey, that'l do
[bravo] Mark
If you are unsure of forum etiquette check here faq796-2540
 
I am trying to make a data connection include file
whitch i can paste into all my pages
 
The best way would probably be to have a data layer that the Front end connects to to get data. That layer would then use a common connection to connect get the data and pass it back to the calling method.

Include files are not supported with asp.net. Mostly they were used to provide some common functionality to multiple pages. To provide common functionality to multiple pages now you can use Web User Controls. Simply a control that you have built. Once finished you can include it in any of your pages. Any changes made to the control will show up in the pages it is used on.

As for the data connection in my projects I put the connection string into the web.config file. Then in my Data Layer class I make a global (to that class only) data connection object. When I need data I open that object and close it when I am done getting the data I need.

Hope this has helped you. Feel free to post if I went off on a tangent. That'l do donkey, that'l do
[bravo] Mark
If you are unsure of forum etiquette check here faq796-2540
 
I digress (or whatever word suits) Include files do work. thread855-505569
I still however suggest the methods I posted above. That'l do donkey, that'l do
[bravo] Mark
If you are unsure of forum etiquette check here faq796-2540
 
yeah, for something like a dataconnection, having a data access or data tier is the ideal.

my .02

D
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top