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;
using System.Configuration;
namespace cqjt
{
/// <summary>
/// cqjt 的摘要说明。
/// </summary>
public class cqjt : System.Web.UI.Page
{
protected System.Web.UI.WebControls.DataList GgList;
protected System.Web.UI.WebControls.DataList zxdtList;
protected System.Web.UI.WebControls.DataList zxwjList;
protected System.Web.UI.WebControls.Label myLabel;
public string Ip_address;
public string dxdate;
public string zong;
private static String ConnectionString=ConfigurationSettings.AppSettings["ConnStr"];
private void Page_Load(object sender, System.EventArgs e)
{
Ip_address = Request.ServerVariables["REMOTE_ADDR"];
dxdate=System.DateTime.Today.ToString("yyyy-MM-dd");
if(!Page.IsPostBack)// 在此处放置用户代码以初始化页面
{
gettongjicunchu();
getGgList();//公告栏
getzxdtList();//最新动态
getwjList();
gettongji();//最新动态
}
}
private void getGgList() //取得公告数据
{
SqlConnection myConnection = new SqlConnection(ConnectionString);//取连接字符串,建立连接
SqlDataAdapter SqlDataAdapter1 = new SqlDataAdapter();
SqlDataAdapter1.SelectCommand=new SqlCommand("SELECT top 5 newid,title,convert(char(10),dateandtime,120) dateandtime FROM jtnews where dtionid=1 ORDER BY dateandtime DESC ",myConnection);
DataSet DataSet1=new DataSet();
try
{
SqlDataAdapter1.Fill(DataSet1,"jtnews");
}
catch (SqlException e1)
{
Response.Write(e1);
}
GgList.DataSource=DataSet1;
GgList.DataBind();
}
private void gettongjicunchu()
{
SqlConnection myConnection =new SqlConnection(ConnectionString);
String sql="select * from tongji where ip='"+Ip_address+"'and dxdate='"+dxdate+"'" ;
SqlCommand myComm=new SqlCommand(sql,myConnection);
SqlDataReader rs=myComm.ExecuteReader();
if (!rs.Read())
{
SqlCommand SqlComm2=new SqlCommand("addtongji",myConnection);
SqlComm2.CommandType=CommandType.StoredProcedure;
SqlComm2.Parameters.Add(new SqlParameter("@ip",SqlDbType.NVarChar,50)); //调用并设置存储过程参数
SqlComm2.Parameters["@ip"].Value = Ip_address;
//获得新闻内容
SqlComm2.Parameters.Add(new SqlParameter("@dxdate",SqlDbType.NVarChar,50));
SqlComm2.Parameters["@dxdate"].Value =dxdate;
}
}
private void gettongji()
{
SqlConnection myConnection =new SqlConnection(ConnectionString);
String sql="select count(*) as zong from tongji" ;
SqlCommand myComm=new SqlCommand(sql,myConnection);
SqlDataReader rs=myComm.ExecuteReader();
while(rs.Read())
{
zong= rs["zong"].ToString();
}
//SqlDataReader rs=myComm.ExecuteReader();//后还要让游标下移动
}
private void getzxdtList() //取得最新动态数据
{
SqlConnection myConnection = new SqlConnection(ConnectionString);//取连接字符串,建立连接
SqlDataAdapter SqlDataAdapter1 = new SqlDataAdapter();
SqlDataAdapter1.SelectCommand=new SqlCommand("SELECT top 5 newid,title,convert(char(10),dateandtime,120) dateandtime FROM jtnews where developmentid=1 ORDER BY dateandtime DESC ",myConnection);
DataSet DataSet1=new DataSet();
try
{
SqlDataAdapter1.Fill(DataSet1,"jtnews");
}
catch (SqlException e1)
{
Response.Write(e1);
}
zxdtList.DataSource=DataSet1;
zxdtList.DataBind();
}
private void getwjList() //取得最新动态数据
{
SqlConnection myConnection = new SqlConnection(ConnectionString);//取连接字符串,建立连接
SqlDataAdapter SqlDataAdapter1 = new SqlDataAdapter();
SqlDataAdapter1.SelectCommand=new SqlCommand("SELECT top 5 newid,title,convert(char(10),dateandtime,120) dateandtime FROM jtnews where classname='政府文件' ORDER BY dateandtime DESC ",myConnection);
DataSet DataSet1=new DataSet();
try
{
SqlDataAdapter1.Fill(DataSet1,"jtnews");
}
catch (SqlException e1)
{
Response.Write(e1);
}
zxwjList.DataSource=DataSet1;
zxwjList.DataBind();
}
#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
}
}
while(rs.Read())
为什么我第一运行正常,第二次运行就出错了
高手指点一下好吗?就说这行已经关闭
如标题一样的错误
[此贴子已经被作者于2006-10-18 17:18:01编辑过]