C
Charles Stanley
Hi all,
I'm new to C#, and have two pretty simple questions:
I have a class, in a .cs file by itself. I need to make use of the sole
function in this class in another .cs file. Here's the code, filename
bannertrack.cs
First question - the function "LogImpr" users ServerVariables["REMOTE_ADDR"]
+ "')"; The compiler tells me that this is not included in the namespace.
??
Second question - How do I call this function from another .cs file?
namespace internetdating.bannertracking.bannertrack
{
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data.Odbc;
using System.Configuration;
/// <summary>
/// STUFF HERE
/// </summary>
public class bannertrack: System.Web.UI.Page
{
public void LogImpr(System.Web.UI.WebControls.AdCreatedEventArgs e)
{
String dsn = ConfigurationSettings.AppSettings["idate"]; //Take
connectionstring from Web.Config
OdbcConnection myConnection = new OdbcConnection(dsn);
string InsertStr = "insert into impressions (LinkURL, Timestamp, IP) Values
('" + e.NavigateUrl +
"',NOW()" + ", '" + ServerVariables["REMOTE_ADDR"] + "')";
OdbcCommand myCommand = new OdbcCommand(InsertStr, myConnection);
myCommand.Connection.Open();
try
{
myCommand.ExecuteNonQuery();
}
finally
{
myCommand.Connection.Close();
}
}
}
}
I'm new to C#, and have two pretty simple questions:
I have a class, in a .cs file by itself. I need to make use of the sole
function in this class in another .cs file. Here's the code, filename
bannertrack.cs
First question - the function "LogImpr" users ServerVariables["REMOTE_ADDR"]
+ "')"; The compiler tells me that this is not included in the namespace.
??
Second question - How do I call this function from another .cs file?
namespace internetdating.bannertracking.bannertrack
{
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data.Odbc;
using System.Configuration;
/// <summary>
/// STUFF HERE
/// </summary>
public class bannertrack: System.Web.UI.Page
{
public void LogImpr(System.Web.UI.WebControls.AdCreatedEventArgs e)
{
String dsn = ConfigurationSettings.AppSettings["idate"]; //Take
connectionstring from Web.Config
OdbcConnection myConnection = new OdbcConnection(dsn);
string InsertStr = "insert into impressions (LinkURL, Timestamp, IP) Values
('" + e.NavigateUrl +
"',NOW()" + ", '" + ServerVariables["REMOTE_ADDR"] + "')";
OdbcCommand myCommand = new OdbcCommand(InsertStr, myConnection);
myCommand.Connection.Open();
try
{
myCommand.ExecuteNonQuery();
}
finally
{
myCommand.Connection.Close();
}
}
}
}