删除DataTable中的第一行

时间:2015-04-12 19:43:38

标签: c# asp.net

我试图在另一个函数

中创建一个新数据表(来自另一个数据表)没有成功
Session["Tissues"] = tableword;// I dont load them again
Session["Randomtable"] = tableword;

基本上我需要的是在一个表中用后面的代码删除dataTable的第一行。

private void Question_table()
{
    if (Session["Tissues"] != null)
    {           
        DataTable table_word =  (DataTable)Session["Tissues"];
        DataTable table_random = (DataTable)Session["Randomtable"];        
        GridView3.DataSource = table_random;
        GridView3.DataBind();

             string q_name = "";
            DataRow row = table_word.Rows[0];
            if (row["name"] != null) // This will check the null values also (if you want to check).
            {
                // Do whatever you want.
                q_name = row["name"].ToString();

            }
            if (row["image"] != null) // This will check the null values also (if you want to check).
            {
                q_image = row["image"].ToString();
            }
            Next_Question(q_name, q_image, table_random);
            Label3.Text = q_name;
            Label4.Text = q_image;
            row.Delete();
            // table_word.Rows.RemoveAt(0);
           // table_word.Rows.Remove(row);
          //  table_word.Rows.Remove(table_word.Rows[0]); 
           Session["Tissues"] = table_word;

    }
}

我打电话

Question_table();
单击图像按钮后

问题是当我尝试只删除一个数据表的一行但删除了两个数据表的内容时。

1 个答案:

答案 0 :(得分:0)

由于datatablereference type并且有以下语句,这意味着指向单个内存,即表字地址。

Session["Tissues"] = tableword;// I dont load them again
Session["Randomtable"] = tableword;

因此,当您从会话中检索并删除一行时,它会将其从第2点和第2点删除到相同的数据。

相关问题