标题:关于读取数据库信息问题,怎么读?
只看楼主
garyboy520
Rank: 1
等 级:新手上路
帖 子:36
专家分:0
注 册:2006-5-16
 问题点数:0 回复次数:0 
关于读取数据库信息问题,怎么读?
为什么我加了这段代码了就不能修改内容了?原来是可以的!!

private void Page_Load(object sender, System.EventArgs e)
{
string StrSql="";

conn.open();
StrSql="select * from cpjs where id="+Request.QueryString["id"];
OleDbCommand mycommand=new OleDbCommand(StrSql,conn.dbconn);
OleDbDataReader myReader=mycommand.ExecuteReader();
if(myReader.Read())
{
this.fzmz1.Text=myReader.GetString(4);
this.fzys1.Text=myReader.GetString(2);
this.fzjg1.Text=myReader.GetString(3);
this.fzjs1.Text=myReader.GetString(5);
}
else
{
Response.Write ("<script>alert('当前没有记录,请返回!!');history.go(-1);</script>");
}

myReader.Close();
mycommand.Dispose();
conn.close();
}



原来代码如下:
namespace flashfz.qruanadmin
{
/// <summary>
/// addcpjs 的摘要说明。
/// </summary>
public class editcpjs : System.Web.UI.Page
{
protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator1;
protected System.Web.UI.WebControls.TextBox fzys1;
protected System.Web.UI.WebControls.RequiredFieldValidator Requiredfieldvalidator2;
protected System.Web.UI.WebControls.TextBox fzjg1;
protected System.Web.UI.WebControls.RequiredFieldValidator Requiredfieldvalidator3;
protected System.Web.UI.WebControls.TextBox fzjs1;
protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator4;
protected System.Web.UI.HtmlControls.HtmlInputButton Submit2;
protected System.Web.UI.WebControls.TextBox fzmz1;
protected config conn=new config();

private void Page_Load(object sender, System.EventArgs e)
{
string StrSql="";

conn.open();
StrSql="select * from cpjs where id="+Request.QueryString["id"];
OleDbCommand mycommand=new OleDbCommand(StrSql,conn.dbconn);
OleDbDataReader myReader=mycommand.ExecuteReader();
if(myReader.Read())
{
this.fzmz1.Text=myReader.GetString(4);
this.fzys1.Text=myReader.GetString(2);
this.fzjg1.Text=myReader.GetString(3);
this.fzjs1.Text=myReader.GetString(5);
}
else
{
Response.Write ("<script>alert('当前没有记录,请返回!!');history.go(-1);</script>");
}

myReader.Close();
mycommand.Dispose();
conn.close();
}

#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.Submit2.ServerClick += new System.EventHandler(this.Submit2_ServerClick);
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion

private void Submit2_ServerClick(object sender, System.EventArgs e)
{
string Sql="";

conn.open();
Sql="UPDATE cpjs set fzmz='"+this.fzmz1.Text+"',fzys='"+this.fzys1.Text+"',fzjg='"+this.fzjg1.Text+"',fzjs='"+this.fzjs1.Text+"' where id="+Request.QueryString["id"];

OleDbCommand mycommand=new OleDbCommand(Sql,conn.dbconn);
mycommand.ExecuteNonQuery();
mycommand.Dispose();
conn.close();
Response.Write("<script>alert('修改成功!!');location.href='cpjs.aspx';</script>");

}
}
}

搜索更多相关主题的帖子: 数据库 myReader StrSql mycommand 
2006-05-22 09:03



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-66153-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.709776 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved