修改数据问题
数据没有被修改,是什么问题?
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Data.OleDb;
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 WebApplication1
{
/// <summary>
/// WebForm3 的摘要说明。
/// </summary>
public class WebForm3 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Button b;
protected System.Web.UI.WebControls.Button 提交;
protected System.Web.UI.WebControls.Label Span1;
protected System.Web.UI.WebControls.TextBox GRE;
protected System.Web.UI.WebControls.TextBox 学号;
protected System.Web.UI.WebControls.Label Label1;
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
string id;
id = Request.QueryString["id"];
stringconnStr= "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+Server.MapPath("grade.mdb");
OleDbConnection myConnection = new OleDbConnection(connStr);
myConnection.Open();
string sql="select * from grade where 编号 = "+id+" ";
OleDbCommand cmd = new OleDbCommand(sql, myConnection);
OleDbDataReader read = cmd.ExecuteReader();
if(read.Read())
{
学号.Text=read["学号"].ToString();
GRE.Text=read["GRE"].ToString();
}
myConnection.Close();
read.Close();
}
#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);
}
#endregion
public void B_Click(object sender, System.EventArgs e)
{
string connStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+Server.MapPath("grade.mdb");
OleDbConnection myConnection2 = new OleDbConnection(connStr);
myConnection2.Open();
string id;
id = Request.QueryString["id"];
OleDbCommand myCommand = new OleDbCommand("UPDATE grade set 学号="+this.学号.Text+", GRE="+this.GRE.Text+" where 编号 = "+id+"", myConnection2);
myCommand.ExecuteNonQuery();
myConnection2.Close();
Response.Redirect("WebForm1.aspx") ;
}
public void reset_Click(Object sender,EventArgs e)
{
学号.Text="";
GRE.Text="";
}
}
}
参考答案:不懂..顶下/.~