一个天才顶不上十个笨蛋!
书山有路勤为径,学海无涯友相伴。
我的E-mail:mylover624@.cn
我的正个的代码,绿字部分那么写对吗,
红字部分需要改,要不CSC提示委托不匹配
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;
namespace patent.system
{
/// <summary>
/// BigClass 的摘要说明。
/// </summary>
public class BigClass : System.Web.UI.Page
{
protected System.Web.UI.WebControls.DataGrid DataGrid1;
OleDbConnection conn=new OleDbConnection();
OleDbCommand cmd=new OleDbCommand();
DataSet ds=new DataSet();
OleDbDataAdapter da=new OleDbDataAdapter();
private void Page_Load(object sender, System.EventArgs e)
{
string Broadid=Convert.ToString(Request["Broadid"]);
string del=Convert.ToString(Request["del"]);
if(del=="yes")
{
int id=Convert.ToInt32(Request["id"]);
conn=new OleDbConnection("provider=Microsoft.Jet.OLEDB.4.0;data source="+Server.MapPath("../data/patent.mdb"));
conn.Open();
cmd=new OleDbCommand("delete from "+Broadid+" where id=?",conn);
OleDbParameter ParaID=new OleDbParameter("@id",OleDbType.Integer);
ParaID.Direction=ParameterDirection.Input;
cmd.Parameters.Add(ParaID);
ParaID.Value=id;
cmd.ExecuteNonQuery();
conn.Close();
conn.Dispose();
cmd.Dispose();
Response.Redirect("Display.aspx?Broadid="+Broadid);
}
else
{
try
{
conn.ConnectionString="provider=Microsoft.Jet.OLEDB.4.0;data source="+Server.MapPath("../data/patent.mdb");
cmd.Connection=conn;
cmd.CommandText="select * from "+Broadid;
da.SelectCommand=cmd;
da.Fill(ds,Broadid);
conn.Close();
DataGrid1.DataSource=ds.Tables[Broadid];
DataGrid1.DataBind();
}
catch(Exception ex)
{
Response.Write(ex.Message);
}
}
}
private void DataGrid1_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
{
string Broadid=Convert.ToString(Request["Broadid"]);
this.DataGrid1.CurrentPageIndex = e.NewPageIndex;
conn.ConnectionString="provider=Microsoft.Jet.OLEDB.4.0;data source="+Server.MapPath("../data/patent.mdb");
cmd.Connection=conn;
cmd.CommandText="select * from "+Broadid;
da.SelectCommand=cmd;
da.Fill(ds,Broadid);
conn.Close();
DataGrid1.DataSource=ds.Tables[Broadid];
DataGrid1.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);
this.DataGrid1.PageIndexChanged += new System.EventHandler(this.DataGrid1_PageIndexChanged);
}
#endregion
}
}