我想在一个dataset中先检查是否存在表"product",如果存在就从dataset中移除他,再用SqlDataAdapter重新生成这个表加到dataset中....
我该怎么做啊...?!
谢谢

解决方案 »

  1.   

    DataSet s = null;
    if (s.Tables.Contains("product"))
    {
        //todo
    }
      

  2.   

    示例
    [Visual Basic, C#] 以下示例测试 DataTableCollection 中是否存在名为“Suppliers”的表。[Visual Basic] 
    Private Sub TestForTableName()
       Dim dSet As DataSet
       ' Get the DataSet of a DataGrid.
       dSet = CType(DataGrid1.DataSource, DataSet)
       ' Get the DataTableCollection through the Tables property.
       Dim tablesCol As DataTableCollection
       tablesCol = dSet.Tables
       ' Check if the named table exists.
       If tablesCol.Contains("Suppliiers") Then 
          MessageBox.Show("Table named Suppliers exists")
       End If
    End Sub[C#] 
    private void TestForTableName()
    {
       DataSet dSet;
       // Get the DataSet of a DataGrid.
       dSet = (DataSet)DataGrid1.DataSource;
       // Get the DataTableCollection through the Tables property.
       DataTableCollection tablesCol = dSet.Tables;
       // Check if the named table exists.
       if (tablesCol.Contains("Suppliiers")) 
          MessageBox.Show("Table named Suppliers exists");
    }