Click to See Complete Forum and Search --> : problem with include file


bhuraasif
May 21st, 2007, 07:17 AM
hello everyone

in 2003 ASP.NET (C#). i created one include file(for_date.inc)

code in this file are given below.this is working very fine.as i want.

but the problem is that this same code i copied in another application in 2005(C#). it doesnt run.

Please help me out and show me how to write inc file in 2005 (C#).

waiting fo reply.


<%@ Import namespace=" System.Web.UI.HtmlControls "%>
<%@ Import namespace="System.Web.UI.WebControls "%>
<%@ Import namespace="System.Web.UI "%>
<%@ Import namespace="System.Web.SessionState "%>
<%@ Import namespace="System.Web "%>
<%@ Import namespace="System.Configuration "%>
<%@ Import namespace="System.Drawing "%>
<%@ Import namespace="System.Data.SqlClient "%>
<%@ Import namespace="System.Data "%>
<%@ Import namespace="System.ComponentModel "%>
<%@ Import namespace=" System.Collections "%>

<META http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<LINK href=../styles/styles.css type=text/css rel=stylesheet>
<script language=JavaScript src=../scripts/script.js type=text/JavaScript></script>
<%
SqlConnection conbiz = new SqlConnection(ConfigurationSettings.AppSettings["DBConnection"]);
conbiz.Open();
SqlCommand cmdbiz = new SqlCommand();
cmdbiz.CommandType = CommandType.StoredProcedure;
cmdbiz.CommandText = "SP_Inc";
cmdbiz.Connection= conbiz;

SqlDataAdapter sda = new SqlDataAdapter(cmdbiz);
DataSet dst = new DataSet();
sda.Fill(dst);

repbiz.DataSource = dst.Tables[2];
repbiz.DataBind();

conne.Close();
%>
<TABLE id="main" cellSpacing="0" cellPadding="0" width="217" border="0" height="418">
<TR>
<TD height="113" width="231" vAlign="top"><FONT size="1"></FONT>
<TABLE id="Table4" borderColor="#ffffff" cellSpacing="0" cellPadding="0" width="215" border="0">
<TR bgcolor="#cccccc">
<TD height="18">
<P align="center"><STRONG><FONT face="Tahoma" color="#660000" size="2">LATEST BUSINESS ARTICLES</FONT></STRONG></P>
</TD>
</TR>
<TR>
<td width="245" height="74">
<asp:Repeater id="repbiz" runat="server">
<ItemTemplate>
<a href='../Business/<%#DataBinder.Eval(Container.DataItem,"page_path")%>' class="linkingtext" name='<%#DataBinder.Eval(Container.DataItem,"news_map")%>' target="_blank">
-
<%#DataBinder.Eval(Container.DataItem,"news_head")%>
<br>
</a>
</ItemTemplate>
</asp:Repeater>
</td>
</TR>
<tr>
<td align="right"><a href="files/Newslink.aspx?newslink=Business" class="linkingtext">more..</a></td>
</tr>
</TABLE>
</TD>
</TR>
</TABLE>

mcmcom
May 21st, 2007, 08:51 PM
it would be easier for you to put this in code-behind. .inc files have no real use anymore they were mostly for use in classic asp.

Anyways aside from that i think your problem is the configuration settings.

.NEt 2.0 uses ConfigurationManager class instead of ConfigurationSettings.

your connection string will need to be re-written. Google "Connection Strings in Vs 2005" or ConnectionManager + Connection Strings and you will see many examples

basically this line

ConfigurationSettings.AppSettings["DBConnection"]);


should look (sort of) like this


ConfigurationManager.ConnectionStrings["DBConnection"].ConnectionString);


and also some minor tag changes to the web.config to facilitate this call.

hth,
mcm