www.cs

来自「这是一个用ASP加SQL做的新闻网站,里面有不少的新闻可以浏览,共享的.」· CS 代码 · 共 49 行

CS
49
字号
using System; 
using System.Data; 
using System.Data.OleDb; 
using System.Web.UI; 
using System.Web.UI.WebControls; 
using System.Web.UI.HtmlControls; 


namespace www
{
	public class MyCodeBehind : Page 
	{ 
		public DataGrid  MyList; 
		public DataGrid  MyList1; 
	  

		private void Page_Load(Object sender, EventArgs e) 
		{
	   
			if(!IsPostBack) 
			{

				OleDbConnection myConnection = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source="+ Server.MapPath("new.mdb"));   
				OleDbDataAdapter myCommand = new  OleDbDataAdapter("select top 12 news.* FROM news WHERE typeid=1 order by shijian desc", myConnection);
                OleDbDataAdapter myCommand1 = new  OleDbDataAdapter("select top 12 news.* FROM news WHERE typeid=2 order by shijian desc", myConnection);
				DataSet ds = new DataSet();
				myCommand.Fill(ds, "aa");
                myCommand1.Fill(ds, "bb");
				MyList.DataSource = ds.Tables["aa"].DefaultView;
                MyList1.DataSource = ds.Tables["bb"].DefaultView;
				MyList.DataBind();
				MyList1.DataBind();
			}
		}
       
       
		protected string FormatString(string str) 
		{ 
			str=str.Replace(" ","  "); 
			str=str.Replace("<","&lt;"); 
			str=str.Replace(">","&gt;"); 
			str=str.Replace('\n'.ToString(),"<br>"); 
			return str; 
		} 
	

	} 
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?