我的代码:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;namespace user
{
/// <summary>
/// rework 的摘要说明。
/// </summary>
public class rework : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label Label1;
protected System.Web.UI.WebControls.Label Label2;
protected System.Web.UI.WebControls.Label Label3;
protected System.Web.UI.WebControls.Label Label4;
protected System.Web.UI.WebControls.Label Label5;
protected System.Web.UI.WebControls.Label Label6;
protected System.Web.UI.WebControls.Label Label7;
protected System.Web.UI.WebControls.Label Label8;
protected System.Web.UI.WebControls.Label Label9;
protected System.Web.UI.WebControls.Label Label10;
protected System.Web.UI.WebControls.Label Label11;
protected System.Web.UI.WebControls.HyperLink HyperLink1;
protected System.Web.UI.WebControls.Button Button1;
protected System.Web.UI.WebControls.Label Label12;
protected System.Web.UI.WebControls.Label lmessage;
protected System.Web.UI.WebControls.TextBox tname;
protected System.Web.UI.WebControls.TextBox tyw;
protected System.Web.UI.WebControls.TextBox tdz;
protected System.Web.UI.WebControls.TextBox tdh;
protected System.Web.UI.WebControls.TextBox tcz;
protected System.Web.UI.WebControls.TextBox tyb;
protected System.Web.UI.WebControls.TextBox tmail;
protected System.Web.UI.WebControls.TextBox twz;
protected System.Web.UI.WebControls.TextBox tff;
protected System.Web.UI.WebControls.TextBox tzp;
protected System.Web.UI.WebControls.TextBox tjj;
protected ClassConn myconn; string id;
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
id=Request["myid"].ToString();
myconn=new ClassConn();
string sql="select * from pds.corp";
DataSet ds=new DataSet();
ds=myconn.DataSets(sql);
tname.Text= Convert.ToString(ds.Tables[0].Rows[0]["corp_name"]);
tyw.Text= Convert.ToString(ds.Tables[0].Rows[0]["main_business"]);
tdz.Text= Convert.ToString(ds.Tables[0].Rows[0]["corp_addr"]);
tdh.Text= Convert.ToString(ds.Tables[0].Rows[0]["corp_phone"]);
tcz.Text= Convert.ToString(ds.Tables[0].Rows[0]["fax"]);
tyb.Text= Convert.ToString(ds.Tables[0].Rows[0]["post_code"]);
tmail.Text= Convert.ToString(ds.Tables[0].Rows[0]["corp_email"]);
twz.Text= Convert.ToString(ds.Tables[0].Rows[0]["website"]);
tff.Text= Convert.ToString(ds.Tables[0].Rows[0]["fee_phone"]);
tzp.Text= Convert.ToString(ds.Tables[0].Rows[0]["corp_picture"]);
tjj.Text= Convert.ToString(ds.Tables[0].Rows[0]["brief"]);
} #region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.Button1.Click += new System.EventHandler(this.Button1_Click);
this.Load += new System.EventHandler(this.Page_Load); }
#endregion private void Button1_Click(object sender, System.EventArgs e)
{
try
{
myconn=new ClassConn();
string sql="update pds.corp set crop_name='"+tname.Text+"',main_business='"+tyw.Text+"',corp_addr='"+tdz.Text+"',corp_phone='"+tdh.Text+"',fax='"+tcz.Text+"',post_code='"+tyb.Text+"',corp_email='"+tmail.Text+"',website='"+twz.Text+"',fee_phone='"+tff.Text+"',corp_picture='"+tzp.Text+"',brief='"+tjj.Text+"' where corp_id='"+id+"'";
myconn.execsql(sql);
myconn.CloseDB();
lmessage.Text="更新成功请返回.";
}
catch
{
lmessage.Text="更新失败请与管理员联系!";
}
}
}
}
====
ClassConn.cs的代码
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;namespace user
{
/// <summary>
/// ClassConn 的摘要说明。
/// </summary>
public class ClassConn
{
public ClassConn()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
public SqlConnection connection;
public void OpenDB()
{
connection= new SqlConnection(System.Configuration.ConfigurationSettings.AppSettings["connstring"]);
connection.Open();
}
public void CloseDB()
{
connection.Dispose();
connection.Close();
}
public void execsql(string sql)
{
OpenDB();
SqlCommand cmd=new SqlCommand(sql,connection);
cmd.ExecuteNonQuery();
CloseDB();
}
public DataSet DataSets(string query)
{
OpenDB();
SqlDataAdapter rs=new SqlDataAdapter(query,connection);
DataSet ds=new DataSet();
rs.Fill(ds);
return ds;
} }
}
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;namespace user
{
/// <summary>
/// rework 的摘要说明。
/// </summary>
public class rework : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label Label1;
protected System.Web.UI.WebControls.Label Label2;
protected System.Web.UI.WebControls.Label Label3;
protected System.Web.UI.WebControls.Label Label4;
protected System.Web.UI.WebControls.Label Label5;
protected System.Web.UI.WebControls.Label Label6;
protected System.Web.UI.WebControls.Label Label7;
protected System.Web.UI.WebControls.Label Label8;
protected System.Web.UI.WebControls.Label Label9;
protected System.Web.UI.WebControls.Label Label10;
protected System.Web.UI.WebControls.Label Label11;
protected System.Web.UI.WebControls.HyperLink HyperLink1;
protected System.Web.UI.WebControls.Button Button1;
protected System.Web.UI.WebControls.Label Label12;
protected System.Web.UI.WebControls.Label lmessage;
protected System.Web.UI.WebControls.TextBox tname;
protected System.Web.UI.WebControls.TextBox tyw;
protected System.Web.UI.WebControls.TextBox tdz;
protected System.Web.UI.WebControls.TextBox tdh;
protected System.Web.UI.WebControls.TextBox tcz;
protected System.Web.UI.WebControls.TextBox tyb;
protected System.Web.UI.WebControls.TextBox tmail;
protected System.Web.UI.WebControls.TextBox twz;
protected System.Web.UI.WebControls.TextBox tff;
protected System.Web.UI.WebControls.TextBox tzp;
protected System.Web.UI.WebControls.TextBox tjj;
protected ClassConn myconn; string id;
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
id=Request["myid"].ToString();
myconn=new ClassConn();
string sql="select * from pds.corp";
DataSet ds=new DataSet();
ds=myconn.DataSets(sql);
tname.Text= Convert.ToString(ds.Tables[0].Rows[0]["corp_name"]);
tyw.Text= Convert.ToString(ds.Tables[0].Rows[0]["main_business"]);
tdz.Text= Convert.ToString(ds.Tables[0].Rows[0]["corp_addr"]);
tdh.Text= Convert.ToString(ds.Tables[0].Rows[0]["corp_phone"]);
tcz.Text= Convert.ToString(ds.Tables[0].Rows[0]["fax"]);
tyb.Text= Convert.ToString(ds.Tables[0].Rows[0]["post_code"]);
tmail.Text= Convert.ToString(ds.Tables[0].Rows[0]["corp_email"]);
twz.Text= Convert.ToString(ds.Tables[0].Rows[0]["website"]);
tff.Text= Convert.ToString(ds.Tables[0].Rows[0]["fee_phone"]);
tzp.Text= Convert.ToString(ds.Tables[0].Rows[0]["corp_picture"]);
tjj.Text= Convert.ToString(ds.Tables[0].Rows[0]["brief"]);
} #region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.Button1.Click += new System.EventHandler(this.Button1_Click);
this.Load += new System.EventHandler(this.Page_Load); }
#endregion private void Button1_Click(object sender, System.EventArgs e)
{
try
{
myconn=new ClassConn();
string sql="update pds.corp set crop_name='"+tname.Text+"',main_business='"+tyw.Text+"',corp_addr='"+tdz.Text+"',corp_phone='"+tdh.Text+"',fax='"+tcz.Text+"',post_code='"+tyb.Text+"',corp_email='"+tmail.Text+"',website='"+twz.Text+"',fee_phone='"+tff.Text+"',corp_picture='"+tzp.Text+"',brief='"+tjj.Text+"' where corp_id='"+id+"'";
myconn.execsql(sql);
myconn.CloseDB();
lmessage.Text="更新成功请返回.";
}
catch
{
lmessage.Text="更新失败请与管理员联系!";
}
}
}
}
====
ClassConn.cs的代码
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;namespace user
{
/// <summary>
/// ClassConn 的摘要说明。
/// </summary>
public class ClassConn
{
public ClassConn()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
public SqlConnection connection;
public void OpenDB()
{
connection= new SqlConnection(System.Configuration.ConfigurationSettings.AppSettings["connstring"]);
connection.Open();
}
public void CloseDB()
{
connection.Dispose();
connection.Close();
}
public void execsql(string sql)
{
OpenDB();
SqlCommand cmd=new SqlCommand(sql,connection);
cmd.ExecuteNonQuery();
CloseDB();
}
public DataSet DataSets(string query)
{
OpenDB();
SqlDataAdapter rs=new SqlDataAdapter(query,connection);
DataSet ds=new DataSet();
rs.Fill(ds);
return ds;
} }
}
解决方案 »
- ASP.NET MVC中action给view层的密码框赋值的问题??
- DataList实现翻页
- 这是什么问题?
- 谁有好的asp.net2.0的分页程序啊~ 可以发我一份不
- ~关于数据显示和隐藏的问题,高分请教~~
- 斑马条码打印机
- 求.NET对Excel的操作
- 请问如何定位数据库中符合条件的单元格(不是行或列,是交错项)?比如让符合条件的单元格背景变为红色?
- 如果动态改变IEWebControl Tab的Text显示文本
- 如何在Datagrid中使用“数据可是设置表达式”
- 刚学asp.net,能给我介绍几本好书吗?
- 请教局域网内QQ的聊天记录,想用XML文件来保存...如何做才好..是把一天所有的聊天记录保存成一个文件,还是一个人一个文件好呢????或者有什
改写如下:
if(!this.ispostback)
{
// 在此处放置用户代码以初始化页面
id=Request["myid"].ToString();
myconn=new ClassConn();
string sql="select * from pds.corp";
DataSet ds=new DataSet();
//赋值
....
....
}
if(!IsPostBack)
{
//.拌定数据
}
if(!IsPostBack)
{
}
我调试了没问题
if(!this.ispostback)
也不可以
你确信更新语句执行了吗?
问题是你上面的程序明显是因为没有写在ispostback中才引起的,如果加了以后仍然没有正确更新,那肯定是你的语句有问题
一下就可以了