更新时间:2023-11-07 19:56:58
您是否在每个会话中都创建DataTable的新实例?
如果为true,为什么要在DataTable中使用静态成员?我认为您正在为每个用户使用相同的数据表.
尝试创建一个新的DataTable实例并禁用静态成员,它可以解决问题.
在此示例中,我更改了DataTable类的名称,因为它与原始DataTable相同.
例如:
Are you creating a new instance of DataTable in every session?
If true, why you''re using the static member in DataTable? I think that you''re using the same datatable for every user.
Try to create a new instance of DataTable and disable the static member, It can solve the problem.
For this example, I changed the name of DataTable class, because it''s the same that the original DataTable.
Ex:
//Classpublic
class MyDataTable
{
public DataTable dt;
public DataTable()
{
dt = new DataTable();
dt.Columns.Add("Col1");
dtColumns.Add("Col2");
}
}
//Web-Page
protected void btSave_Click()
{ //Code to add data to datatable.
MyDataTable dt = new MyDataTable();
MyDataTable.dt.Rows.Add(DataRows);
Session["DataTable"] = MyDataTable.dt;
// saving dataTable to session.
Grid.DataSource = (DataTable)Session["DataTable"];
}
是的,您删除了
yes, you remove the
public static DataTable dt
到
to
public DataTable dt