<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>无标题页</title>
</head>
<body>
<form runat="server">
<div> <asp:Label runat="server" Text="Label"></asp:Label>
<asp:GridView runat="server">
</asp:GridView>
<asp:Label runat="server" Text="Label"></asp:Label>
<asp:GridView runat="server">
</asp:GridView>
<asp:Button runat="server" Text="恢复值" />
</div>
</form>
</body>
</html>
后台代码
复制代码 代码如下:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using xjy.DAL;
using System.Data.SqlClient;
using System.Data.OracleClient;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
ConnectionStringSettings setting = System.Configuration.ConfigurationManager.ConnectionStrings["ConnectionString1"];
string myStr = setting.ConnectionString;
OraDbHelper myora = new OraDbHelper(myStr);
DataTable t1 = new DataTable();
Label1.Text = "更新前的值";
t1 = myora.ExecuteDataTable("select art_no,descr from article where art_no=8");
GridView1.DataSource = t1;
GridView1.DataBind();
if (myora.ExecuteNonQuery("update article set descr='更新描述测试值' where art_no=8")>0)
{
Label2.Text = "更新后的值";
t1 = myora.ExecuteDataTable("select art_no,descr from article where art_no=8");
GridView2.DataSource = t1;
GridView2.DataBind();
}
}
protected void Button1_Click(object sender, EventArgs e)
{
ConnectionStringSettings setting = System.Configuration.ConfigurationManager.ConnectionStrings["ConnectionString1"];
string myStr = setting.ConnectionString;
OraDbHelper myora = new OraDbHelper(myStr);
DataTable t1 = new DataTable();
if (myora.ExecuteNonQuery("update article set descr='可怜可怜60ML/瓶' where art_no=8") > 0)
{
Label2.Text = "更新后的值";
t1 = myora.ExecuteDataTable("select art_no,descr from article where art_no=8");
GridView2.DataSource = t1;
GridView2.DataBind();
}
}
}
结果: