DataGrid的奇怪问题
各位好,我今天在写程序时,对于DataGrid有一个奇怪问题,老是搞不懂,请各位帮帮忙.问题是这样的,我用DataGrid的 "更新 "按钮,当我连接SQL Server 2000数据库时,当我按下 "更新 "按钮时,能够修改数据库的数据,并将更新数据显示在页面,但当我连接Access数据库时,当我按下 "更新 "按钮时,能够修改数据库的数据,但在页面显示时,不能显示更新的数据,必须刷新一下页面,才能显示修改后的数据,不知是怎么回事,我用的都是同一段代码,只是连接的数据库不同而已,请知道原因的帮我看一下,下面是我的源代码:
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;
using System.Configuration;
using System.Web.Security ;
namespace ShopBookApp
{
public class ShopCart : System.Web.UI.Page
{
protected System.Web.UI.WebControls.DataGrid DataGrid1;
protected System.Web.UI.HtmlControls.HtmlForm Form1;
protected System.Web.UI.WebControls.Panel Panel1;
protected System.Web.UI.WebControls.Panel Panel2;
protected System.Web.UI.WebControls.Panel Panel3;
protected System.Web.UI.WebControls.Label Label2;
public static string proidid;
private void Page_Load(object sender, System.EventArgs e)
{
if(!IsPostBack)
{
BindGrid();
}
}
private void MyDataGrid_Edit(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
if(e.CommandName== "Edit ")
{
DataGrid1.EditItemIndex=(int)e.Item.ItemIndex;
BindGrid();
}
}
private void MyDataGrid_Update(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
if(e.CommandName == "Update ")
{
TableCell itemCel2=e.Item.Cells[2];
proidid=itemCel2.Text;
TextBox quantityTxt;
quantityTxt = (TextBox) e.Item.Cells[3].Controls[0];
string qua=quantityTxt.Text;
OleDbConnection myConnection2 = new OleDbConnection(ConfigurationSettings.AppSettings[ "connstr "]);
myConnection2.Open();
OleDbCommand myCommand2 = new OleDb