谁送份C#的数据库程序学习学习?分不够开新贴送分 发给你一份SQL数据库联接池的代码?要吗? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 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.OleDb;//using System.Configuration;namespace AboutMe.Document{ /// <summary> /// Show 的摘要说明。 /// </summary> public class Show : System.Web.UI.Page { protected DataTable DocumentTable=null; protected System.Web.UI.WebControls.RegularExpressionValidator RegularExpressionValidator1; protected System.Web.UI.WebControls.Label labCount; protected System.Web.UI.WebControls.Label labTop; protected System.Web.UI.WebControls.Label labNext; protected System.Web.UI.WebControls.TextBox txtID; protected System.Web.UI.WebControls.Button butGo; protected System.Web.UI.WebControls.RegularExpressionValidator RegularExpressionValidator2; protected System.Web.UI.WebControls.Label labCount1; protected System.Web.UI.WebControls.Label labTop1; protected System.Web.UI.WebControls.Label labNext1; protected System.Web.UI.WebControls.TextBox txtID1; protected System.Web.UI.WebControls.Button butGo1; protected System.Web.UI.WebControls.Label labError; protected System.Web.UI.WebControls.Label labError1; protected int id=0; protected int Count=0; private void Page_Load(object sender, System.EventArgs e) { id=Convert.ToInt16(Page.Request["id"].ToString()); GetData(id);//显示数据 NewData(id);//更新游览次数 RowCount(); ShowPage(id);//显示标头 } private void ShowPage(int id)//显示标头 { if(id==0) { id=1; } if(id>Count) { id=Count; } labCount.Text=id.ToString()+"/"+Count.ToString(); labCount1.Text=id.ToString()+"/"+Count.ToString(); if(id==1) { labNext.Text="<a href='show.aspx?id="+(id+1)+"'>下一篇</a>"; labNext1.Text="<a href='show.aspx?id="+(id+1)+"'>下一篇</a>"; return; } if (id==Count) { labTop.Text="<a href='show.aspx?id="+(id-1)+"'>上一篇</a>"; labTop1.Text="<a href='show.aspx?id="+(id-1)+"'>上一篇</a>"; return; } labNext.Text="<a href='show.aspx?id="+(id+1)+"'>下一篇</a>"; labNext1.Text="<a href='show.aspx?id="+(id+1)+"'>下一篇</a>"; labTop.Text="<a href='show.aspx?id="+(id-1)+"'>上一篇</a>"; labTop1.Text="<a href='show.aspx?id="+(id-1)+"'>上一篇</a>"; } private void RowCount()//计算记录总数 { //string strConn=ConfigurationSettings.AppSettings["strCon"]; OleDbConnection Conn=new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+Server.MapPath("../Data/AboutMeDB.mdb")); OleDbCommand OleCmd=new OleDbCommand("select count(*) as ReSum from Document",Conn); OleDbDataReader OleDR=null; try { Conn.Open(); OleDR=OleCmd.ExecuteReader(); if (OleDR.Read()) Count=Convert.ToInt16(OleDR["ReSum"].ToString()); } catch(Exception err) { Page.Response.Write(err.Message+"对不起,连接数据库出错!"); Page.Response.End(); } finally { Conn.Close(); OleCmd.Dispose(); OleDR.Close(); } //return Count; } private void GetData(int id)//显示数据 { //string strConn=ConfigurationSettings.AppSettings["strCon"]; OleDbConnection Conn=new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+Server.MapPath("../Data/AboutMeDB.mdb")); OleDbDataAdapter OleCmdDoc=new OleDbDataAdapter("select * from Document where DocumentID="+id,Conn); DataSet OleDS=new DataSet(); try { OleCmdDoc.Fill(OleDS,"Document"); DocumentTable=OleDS.Tables["Document"]; DocumentTable.Rows[0]["DocumentTitle"]=BoxTohtml(DocumentTable.Rows[0]["DocumentTitle"].ToString()); DocumentTable.Rows[0]["DocumentDoc"]=BoxTohtml(DocumentTable.Rows[0]["DocumentDoc"].ToString()); } catch(Exception err) { Page.Response.Write(err.Message+"对不起,连接数据库出错!"); Page.Response.End(); } } private void NewData(int id)//更新游览次数 { //string strConn=ConfigurationSettings.AppSettings["strCon"]; OleDbConnection Conn=new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+Server.MapPath("../Data/AboutMeDB.mdb")); OleDbCommand OleCmd=new OleDbCommand("update Document set DocumentNumber=DocumentNumber+1 where DocumentID="+id,Conn); try { Conn.Open(); OleCmd.ExecuteNonQuery(); } catch(Exception err) { Page.Response.Write(err.Message+"对不起,连接数据库出错!"); Page.Response.End(); } finally { Conn.Close(); OleCmd.Dispose(); } } private string BoxTohtml(string chr) { if (chr == null) return ""; chr = chr.Trim(); chr = chr.Replace("<","<"); chr = chr.Replace(">",">"); chr=chr.Replace("\n","<br>"); chr=chr.Replace("\t"," "); chr=chr.Replace(" "," "); return (chr); } #region Web Form Designer generated code override protected void OnInit(EventArgs e) { // // CODEGEN:该调用是 ASP.NET Web 窗体设计器所必需的。 // InitializeComponent(); base.OnInit(e); } /// <summary> /// 设计器支持所需的方法 - 不要使用代码编辑器修改 /// 此方法的内容。 /// </summary> private void InitializeComponent() { this.butGo.Click += new System.EventHandler(this.butGo_Click); this.butGo1.Click += new System.EventHandler(this.butGo1_Click); this.Load += new System.EventHandler(this.Page_Load); } #endregion private void butGo1_Click(object sender, System.EventArgs e) { try { int id =Convert.ToInt16(txtID1.Text.Trim()); if (id>Count) id=Count; if (id<=0) id=1; Page.Response.Redirect("show.aspx?id="+id); } catch { labError1.Visible=true; } } private void butGo_Click(object sender, System.EventArgs e) { try { int id=Convert.ToInt16(txtID.Text.Trim()); if (id>Count) id=Count; if (id<=0) id=1; Page.Response.Redirect("show.aspx?id="+id); } catch { labError.Visible=true; } } }} 我和同事刚完成一个项目(Mis and Gis结合)的测试版,你要的话给你,顺便帮我们测试一下。(数据可能比较复杂一些)[email protected] 判断坐标点是否在圆内 Oracle中插入数据的问题求救 rdlc报表一个数据集里我手动绑定了3个表,但一个RDLC页面只能使用一个表。。 批量写数据库带来的问题 .net怎么取客户端的路径?急!急!急! 从数据库下载时,实时获得下载进度 c# 做的程序游戏能嵌入手机中不? 简单的C#语法发问 Java程序员学C#的困惑-C#的namespace与Java的ClassPath的异同? SharpZipLib如何给压缩的文件加密 急问:如何打印datagrid Oracle的数据库连接字符串怎么总是出错?
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.OleDb;
//using System.Configuration;
namespace AboutMe.Document
{
/// <summary>
/// Show 的摘要说明。
/// </summary>
public class Show : System.Web.UI.Page
{
protected DataTable DocumentTable=null;
protected System.Web.UI.WebControls.RegularExpressionValidator RegularExpressionValidator1;
protected System.Web.UI.WebControls.Label labCount;
protected System.Web.UI.WebControls.Label labTop;
protected System.Web.UI.WebControls.Label labNext;
protected System.Web.UI.WebControls.TextBox txtID;
protected System.Web.UI.WebControls.Button butGo;
protected System.Web.UI.WebControls.RegularExpressionValidator RegularExpressionValidator2;
protected System.Web.UI.WebControls.Label labCount1;
protected System.Web.UI.WebControls.Label labTop1;
protected System.Web.UI.WebControls.Label labNext1;
protected System.Web.UI.WebControls.TextBox txtID1;
protected System.Web.UI.WebControls.Button butGo1;
protected System.Web.UI.WebControls.Label labError;
protected System.Web.UI.WebControls.Label labError1;
protected int id=0;
protected int Count=0;
private void Page_Load(object sender, System.EventArgs e)
{
id=Convert.ToInt16(Page.Request["id"].ToString());
GetData(id);//显示数据
NewData(id);//更新游览次数
RowCount();
ShowPage(id);//显示标头
}
private void ShowPage(int id)//显示标头
{
if(id==0)
{
id=1;
}
if(id>Count)
{
id=Count;
}
labCount.Text=id.ToString()+"/"+Count.ToString();
labCount1.Text=id.ToString()+"/"+Count.ToString();
if(id==1)
{
labNext.Text="<a href='show.aspx?id="+(id+1)+"'>下一篇</a>";
labNext1.Text="<a href='show.aspx?id="+(id+1)+"'>下一篇</a>";
return;
}
if (id==Count)
{
labTop.Text="<a href='show.aspx?id="+(id-1)+"'>上一篇</a>";
labTop1.Text="<a href='show.aspx?id="+(id-1)+"'>上一篇</a>";
return;
}
labNext.Text="<a href='show.aspx?id="+(id+1)+"'>下一篇</a>";
labNext1.Text="<a href='show.aspx?id="+(id+1)+"'>下一篇</a>";
labTop.Text="<a href='show.aspx?id="+(id-1)+"'>上一篇</a>";
labTop1.Text="<a href='show.aspx?id="+(id-1)+"'>上一篇</a>";
}
private void RowCount()//计算记录总数
{
//string strConn=ConfigurationSettings.AppSettings["strCon"];
OleDbConnection Conn=new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+Server.MapPath("../Data/AboutMeDB.mdb"));
OleDbCommand OleCmd=new OleDbCommand("select count(*) as ReSum from Document",Conn);
OleDbDataReader OleDR=null;
try
{
Conn.Open();
OleDR=OleCmd.ExecuteReader();
if (OleDR.Read())
Count=Convert.ToInt16(OleDR["ReSum"].ToString());
}
catch(Exception err)
{
Page.Response.Write(err.Message+"对不起,连接数据库出错!");
Page.Response.End();
}
finally
{
Conn.Close();
OleCmd.Dispose();
OleDR.Close();
}
//return Count;
}
private void GetData(int id)//显示数据
{
//string strConn=ConfigurationSettings.AppSettings["strCon"];
OleDbConnection Conn=new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+Server.MapPath("../Data/AboutMeDB.mdb"));
OleDbDataAdapter OleCmdDoc=new OleDbDataAdapter("select * from Document where DocumentID="+id,Conn);
DataSet OleDS=new DataSet();
try
{
OleCmdDoc.Fill(OleDS,"Document");
DocumentTable=OleDS.Tables["Document"];
DocumentTable.Rows[0]["DocumentTitle"]=BoxTohtml(DocumentTable.Rows[0]["DocumentTitle"].ToString());
DocumentTable.Rows[0]["DocumentDoc"]=BoxTohtml(DocumentTable.Rows[0]["DocumentDoc"].ToString());
}
catch(Exception err)
{
Page.Response.Write(err.Message+"对不起,连接数据库出错!");
Page.Response.End();
}
} private void NewData(int id)//更新游览次数
{
//string strConn=ConfigurationSettings.AppSettings["strCon"];
OleDbConnection Conn=new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+Server.MapPath("../Data/AboutMeDB.mdb"));
OleDbCommand OleCmd=new OleDbCommand("update Document set DocumentNumber=DocumentNumber+1 where DocumentID="+id,Conn);
try
{
Conn.Open();
OleCmd.ExecuteNonQuery();
}
catch(Exception err)
{
Page.Response.Write(err.Message+"对不起,连接数据库出错!");
Page.Response.End();
}
finally
{
Conn.Close();
OleCmd.Dispose();
}
} private string BoxTohtml(string chr)
{
if (chr == null)
return "";
chr = chr.Trim();
chr = chr.Replace("<","<");
chr = chr.Replace(">",">");
chr=chr.Replace("\n","<br>");
chr=chr.Replace("\t"," ");
chr=chr.Replace(" "," ");
return (chr);
} #region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN:该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.butGo.Click += new System.EventHandler(this.butGo_Click);
this.butGo1.Click += new System.EventHandler(this.butGo1_Click);
this.Load += new System.EventHandler(this.Page_Load); }
#endregion private void butGo1_Click(object sender, System.EventArgs e)
{
try
{
int id =Convert.ToInt16(txtID1.Text.Trim());
if (id>Count)
id=Count;
if (id<=0)
id=1;
Page.Response.Redirect("show.aspx?id="+id);
}
catch
{
labError1.Visible=true;
}
} private void butGo_Click(object sender, System.EventArgs e)
{
try
{
int id=Convert.ToInt16(txtID.Text.Trim());
if (id>Count)
id=Count;
if (id<=0)
id=1;
Page.Response.Redirect("show.aspx?id="+id);
}
catch
{
labError.Visible=true;
}
}
}
}
[email protected]