我想要保留住原有数据不被替换掉,应该怎样修改,代码如下:
(错误--是每次发生button_Click事件时,都重新创建表吗?)
DataSet DS = new DataSet();
DataTable DT = new DataTable();void DTable()
{
    DT = DS.Tables.Add();
    DataColumn FileNameAll = DT.Columns.Add("文件全名", typeof(string));
    DataColumn FileJ = DT.Columns.Add("文件夹名", typeof(string));
    DataColumn FileName = DT.Columns.Add("文件名", typeof(string));
    DataColumn Src = DT.Columns.Add("路径", typeof(string));
    dataGridView1.DataSource = DT;
}private void 查询button_Click(object sender, EventArgs e)
{
    DTable();
                    
    string[] dir = Directory.GetFiles(Src_textBox.Text, FileName_textBox.Text,                   SearchOption.AllDirectories);    for (int i = 0; i < dir.Length; i++)
    {
row = DT.NewRow();
row["文件全名"] = Path.GetFileName(dir[i]);
row["文件名"] = Path.GetFileNameWithoutExtension(dir[i]);
row["文件夹名"] = new FileInfo(dir[i]).Directory.Name;
row["路径"] = dir[i];
DT.Rows.Add(row);
    }
}

解决方案 »

  1.   

    if(DS.Tables.Count==0){
    DT   =   DS.Tables.Add();

    else

    DT   = DS.Tables[0];

      
    *****************************************************************************
    欢迎使用CSDN论坛专用阅读器 : CSDN Reader(附全部源代码) http://feiyun0112.cnblogs.com/
      

  2.   

    private bool m_Table=false;private   void   查询button_Click(object   sender,   EventArgs   e) 

            if(!m_Table)
            {
               DTable(); 
               m_Table=true;
            }
    }