我是在VS下做了两个网站,我现在想把我的做的这两个小网站整合成一个网站,我把一个网站放在另一个网站的里,重新配置了web.config app文件夹中的CS文件我全部复制到上一个app文件夹下,但是运行的时候,一个网站能正常运行,但是一连接另一个就报错,
异常详细信息: System.NullReferenceException: 未将对象引用设置到对象的实例。源错误:
行 77: protected void Page_Load(object sender, System.EventArgs e)
行 78: {
行 79: myconn=new SqlConnection(Session["str_connection"].ToString());
行 80: Session["title"]="";
行 81: try
源文件: d:\网站信息管理\源代码\ST_EnterpriseOnlineInfoManage\Down\soft\product_default.aspx.cs 行: 79 原文件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.SqlClient;
namespace hchkjgfyxgs
{
/// <summary>
/// Summary description for product.
/// </summary>
public partial class product : System.Web.UI.Page
{
protected const int Record_Per_Page=12; //'定义每一页显示的记录数
protected int nRecCount ; //保存记录总数
protected int nPageCount; //保存总共的数据页面数目
protected int nPage; //存放要浏览当前数据页面号
protected int nStart ; // 存放当前页面的起始记录序号
protected int nEnd; //存放当前页面的终止记录序号
protected int nPageEnd; //存储当前页面的最后一面的序号 protected System.Data.SqlClient.SqlConnection myconn;
protected System.Data.SqlClient.SqlCommand mycomm;
HtmlTableRow myrow;
protected System.Web.UI.WebControls.LinkButton LinkButton1;
protected System.Web.UI.WebControls.LinkButton LinkButton2;
protected System.Web.UI.WebControls.LinkButton LinkButton3;
protected System.Web.UI.WebControls.LinkButton LinkButton4;
HtmlTableCell mycell;
string sqlselect;
string mypic;
protected string Set_daohang()
{
string daohang;
string daohang1;
string daohang2;
string daohang3;
string daohang4;
//string daohang5=null;
daohang1="<A href='product_default.aspx?kind="+Request.Params["kind"]+"&Page=1'><FONT color='#0000f0'>首页</FONT></A>";
daohang2=" <A href='product_default.aspx?kind="+Request.Params["kind"]+"&Page="+(nPage-1)+"'><FONT color='#0000ff'>上一页</FONT></A>";
int l;
l=(nPage-1)/10;
// for(int i=l*10+1;i<=(l+1)*10&&i<=nPageCount;i++)
// {
// daohang5+=" <A href='ziliao_wendang.aspx?id="+Request.Params["id"]+"&Page="+i+"'><FONT color='#0000ff'>"+i+"</FONT></A>";
//
// }
daohang3=" <A href='product_default.aspx?kind="+Request.Params["kind"]+"&Page="+(nPage+1)+"'><FONT color='#0000ff'>下一页</FONT></A> ";
daohang4=" <A href='product_default.aspx?kind="+Request.Params["kind"]+"&Page="+nPageCount+"'><FONT color='#0000ff'>尾页</FONT></A> ";
if( nPage==1 || nPageCount==1)
{
daohang1="首页";
daohang2=" 上一页";
}
if(nPage==nPageCount || nPageCount==1)
{
daohang3=" 下一页";
daohang4=" 尾页";
} daohang=daohang1+daohang2+daohang3+daohang4;
return daohang;
}
protected void Page_Load(object sender, System.EventArgs e)
{
myconn=new SqlConnection(Session["str_connection"].ToString());
Session["title"]="";
try
{
switch(Convert.ToInt32(Request.Params["kind"].ToString()))
{
case 1:
sqlselect="select product_id,product_name,kind,gongneng,pingjia,shijian,"+
"shouquanfangshi from product where kind='asp源码' order by shijian desc";
Session["title"]="最新软件下载"+" "+"asp源码"+" "+"下载";
break;
case 2:
sqlselect="select product_id,product_name,kind,gongneng,pingjia,shijian,"+
"shouquanfangshi from product where kind='php源码'order by shijian desc";
Session["title"]="最新软件下载"+" "+"php源码"+" "+"下载";
break;
case 3:
sqlselect="select product_id,product_name,kind,gongneng,pingjia,shijian,"+
"shouquanfangshi from product where kind='.net源码'order by shijian desc";
Session["title"]="最新软件下载"+" "+".net源码"+" "+"下载";
break;
case 4:
sqlselect="select product_id,product_name,kind,gongneng,pingjia,shijian,"+
"shouquanfangshi from product where kind='jsp源码'order by shijian desc";
Session["title"]="最新软件下载"+" "+"jsp源码"+" "+"下载";
break;
case 5:
sqlselect="select product_id,product_name,kind,gongneng,pingjia,shijian,"+
"shouquanfangshi from product where kind='网页设计'order by shijian desc";
Session["title"]="最新软件下载"+" "+"网页设计"+" "+"下载";
break;
case 6:
sqlselect="select product_id,product_name,kind,gongneng,pingjia,shijian,"+
"shouquanfangshi from product where kind='图象动画'order by shijian desc";
Session["title"]="最新软件下载"+" "+"图象动画"+" "+"下载";
break;
case 7:
sqlselect="select product_id,product_name,kind,gongneng,pingjia,shijian,"+
"shouquanfangshi from product where kind='其他下载' order by shijian desc";
Session["title"]="最新软件下载"+" "+"其他下载"+" "+"下载";
break;
case 8:
sqlselect="select product_id,product_name,kind,gongneng,pingjia,shijian,"+
"shouquanfangshi from product where kind='电子书籍' order by shijian desc";
Session["title"]="最新软件下载"+" "+"电子书籍"+" "+"下载";
break;
}
}
catch
{
sqlselect="select product_id,product_name,kind,gongneng,pingjia,shijian,"+
"shouquanfangshi from product order by shijian desc";
Session["title"]="最新软件下载"+" "+"热门软件下载";
}
SqlDataAdapter mydda=new SqlDataAdapter(sqlselect,myconn);
myconn.Open();
DataSet ds=new DataSet();
mydda.Fill(ds,"product_3");
nPage = Convert.ToInt32 ( Request.Params[ "Page"] );//得到当前页号
try
{
nRecCount=ds.Tables["product_3"].Rows.Count;//得到数据记录总数
}
catch
{
nRecCount = 0;
}
if (nRecCount > 0)
// 确定数据记录要显示的页面数
nPageCount = nRecCount/Record_Per_Page;
if (nRecCount%Record_Per_Page> 0 )
nPageCount += 1;
//确认浏览命令中的页面参数是否越界,如果越界则重置页面序号
if( nPage<1 )nPage = 1 ;
if ( nPage > nPageCount) nPage = nPageCount ;
//确认当前页面的开始记录和终止记录
nStart = Record_Per_Page * ( nPage - 1 );
nEnd = nStart + Record_Per_Page - 1;
if (nEnd > nRecCount - 1 ) nEnd = nRecCount - 1;
//////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////
if(nRecCount==0)
{
myrow=new HtmlTableRow();
mycell=new HtmlTableCell();
mycell.Height="60";
mycell.Controls.Add(new LiteralControl ("<div align=center valign=center heigth=80><font color='#ff0066'>暂无软件</font></div>"));
myrow.Cells.Add(mycell);
Table22.Rows.Add(myrow);
}
异常详细信息: System.NullReferenceException: 未将对象引用设置到对象的实例。源错误:
行 77: protected void Page_Load(object sender, System.EventArgs e)
行 78: {
行 79: myconn=new SqlConnection(Session["str_connection"].ToString());
行 80: Session["title"]="";
行 81: try
源文件: d:\网站信息管理\源代码\ST_EnterpriseOnlineInfoManage\Down\soft\product_default.aspx.cs 行: 79 原文件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.SqlClient;
namespace hchkjgfyxgs
{
/// <summary>
/// Summary description for product.
/// </summary>
public partial class product : System.Web.UI.Page
{
protected const int Record_Per_Page=12; //'定义每一页显示的记录数
protected int nRecCount ; //保存记录总数
protected int nPageCount; //保存总共的数据页面数目
protected int nPage; //存放要浏览当前数据页面号
protected int nStart ; // 存放当前页面的起始记录序号
protected int nEnd; //存放当前页面的终止记录序号
protected int nPageEnd; //存储当前页面的最后一面的序号 protected System.Data.SqlClient.SqlConnection myconn;
protected System.Data.SqlClient.SqlCommand mycomm;
HtmlTableRow myrow;
protected System.Web.UI.WebControls.LinkButton LinkButton1;
protected System.Web.UI.WebControls.LinkButton LinkButton2;
protected System.Web.UI.WebControls.LinkButton LinkButton3;
protected System.Web.UI.WebControls.LinkButton LinkButton4;
HtmlTableCell mycell;
string sqlselect;
string mypic;
protected string Set_daohang()
{
string daohang;
string daohang1;
string daohang2;
string daohang3;
string daohang4;
//string daohang5=null;
daohang1="<A href='product_default.aspx?kind="+Request.Params["kind"]+"&Page=1'><FONT color='#0000f0'>首页</FONT></A>";
daohang2=" <A href='product_default.aspx?kind="+Request.Params["kind"]+"&Page="+(nPage-1)+"'><FONT color='#0000ff'>上一页</FONT></A>";
int l;
l=(nPage-1)/10;
// for(int i=l*10+1;i<=(l+1)*10&&i<=nPageCount;i++)
// {
// daohang5+=" <A href='ziliao_wendang.aspx?id="+Request.Params["id"]+"&Page="+i+"'><FONT color='#0000ff'>"+i+"</FONT></A>";
//
// }
daohang3=" <A href='product_default.aspx?kind="+Request.Params["kind"]+"&Page="+(nPage+1)+"'><FONT color='#0000ff'>下一页</FONT></A> ";
daohang4=" <A href='product_default.aspx?kind="+Request.Params["kind"]+"&Page="+nPageCount+"'><FONT color='#0000ff'>尾页</FONT></A> ";
if( nPage==1 || nPageCount==1)
{
daohang1="首页";
daohang2=" 上一页";
}
if(nPage==nPageCount || nPageCount==1)
{
daohang3=" 下一页";
daohang4=" 尾页";
} daohang=daohang1+daohang2+daohang3+daohang4;
return daohang;
}
protected void Page_Load(object sender, System.EventArgs e)
{
myconn=new SqlConnection(Session["str_connection"].ToString());
Session["title"]="";
try
{
switch(Convert.ToInt32(Request.Params["kind"].ToString()))
{
case 1:
sqlselect="select product_id,product_name,kind,gongneng,pingjia,shijian,"+
"shouquanfangshi from product where kind='asp源码' order by shijian desc";
Session["title"]="最新软件下载"+" "+"asp源码"+" "+"下载";
break;
case 2:
sqlselect="select product_id,product_name,kind,gongneng,pingjia,shijian,"+
"shouquanfangshi from product where kind='php源码'order by shijian desc";
Session["title"]="最新软件下载"+" "+"php源码"+" "+"下载";
break;
case 3:
sqlselect="select product_id,product_name,kind,gongneng,pingjia,shijian,"+
"shouquanfangshi from product where kind='.net源码'order by shijian desc";
Session["title"]="最新软件下载"+" "+".net源码"+" "+"下载";
break;
case 4:
sqlselect="select product_id,product_name,kind,gongneng,pingjia,shijian,"+
"shouquanfangshi from product where kind='jsp源码'order by shijian desc";
Session["title"]="最新软件下载"+" "+"jsp源码"+" "+"下载";
break;
case 5:
sqlselect="select product_id,product_name,kind,gongneng,pingjia,shijian,"+
"shouquanfangshi from product where kind='网页设计'order by shijian desc";
Session["title"]="最新软件下载"+" "+"网页设计"+" "+"下载";
break;
case 6:
sqlselect="select product_id,product_name,kind,gongneng,pingjia,shijian,"+
"shouquanfangshi from product where kind='图象动画'order by shijian desc";
Session["title"]="最新软件下载"+" "+"图象动画"+" "+"下载";
break;
case 7:
sqlselect="select product_id,product_name,kind,gongneng,pingjia,shijian,"+
"shouquanfangshi from product where kind='其他下载' order by shijian desc";
Session["title"]="最新软件下载"+" "+"其他下载"+" "+"下载";
break;
case 8:
sqlselect="select product_id,product_name,kind,gongneng,pingjia,shijian,"+
"shouquanfangshi from product where kind='电子书籍' order by shijian desc";
Session["title"]="最新软件下载"+" "+"电子书籍"+" "+"下载";
break;
}
}
catch
{
sqlselect="select product_id,product_name,kind,gongneng,pingjia,shijian,"+
"shouquanfangshi from product order by shijian desc";
Session["title"]="最新软件下载"+" "+"热门软件下载";
}
SqlDataAdapter mydda=new SqlDataAdapter(sqlselect,myconn);
myconn.Open();
DataSet ds=new DataSet();
mydda.Fill(ds,"product_3");
nPage = Convert.ToInt32 ( Request.Params[ "Page"] );//得到当前页号
try
{
nRecCount=ds.Tables["product_3"].Rows.Count;//得到数据记录总数
}
catch
{
nRecCount = 0;
}
if (nRecCount > 0)
// 确定数据记录要显示的页面数
nPageCount = nRecCount/Record_Per_Page;
if (nRecCount%Record_Per_Page> 0 )
nPageCount += 1;
//确认浏览命令中的页面参数是否越界,如果越界则重置页面序号
if( nPage<1 )nPage = 1 ;
if ( nPage > nPageCount) nPage = nPageCount ;
//确认当前页面的开始记录和终止记录
nStart = Record_Per_Page * ( nPage - 1 );
nEnd = nStart + Record_Per_Page - 1;
if (nEnd > nRecCount - 1 ) nEnd = nRecCount - 1;
//////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////
if(nRecCount==0)
{
myrow=new HtmlTableRow();
mycell=new HtmlTableCell();
mycell.Height="60";
mycell.Controls.Add(new LiteralControl ("<div align=center valign=center heigth=80><font color='#ff0066'>暂无软件</font></div>"));
myrow.Cells.Add(mycell);
Table22.Rows.Add(myrow);
}
你这里应该先判断下这个值是否为空再继续:if(Session["str_connection"]!=null){}