Click here to Skip to main content
16,021,172 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i want to find a datatable in a dataset when exact name is unknown.
i cannot use DataTable abc = set["xyz"]; or xyz[0].

DataTable sweepon = Set.Tables.Contains("sweep-on$");
passtosomemethod(sweepon, true);
Posted

Hi,
Try this:
C#
//ds is your dataset object
foreach (DataTable dt in ds.Tables) {
    //Searching for the table whose name contains "sweep"
    if (dt.TableName.Contains("sweep")) 
    {
        //Console.WriteLine(dt.TableName);
        // do your work here. you found your table name
        passtosomemethod(dt.TableName, true); 
    }
}



--Amit
 
Share this answer
 
v2
C#
private void GetTableNames(DataSet dataSet)
{

string datatablepartialName="xyz";
    // Print each table's TableName.
    foreach(DataTable table in dataSet.Tables)
    {
        If(table.TableName.Contains(datatablepartialName))
{
//then do something
}

    }
}
 
Share this answer
 
Can you check that you have spelld it right with this code:

C#
private void GetTableNames(DataSet dataSet)
{
    // Print each table's TableName.
    foreach(DataTable table in dataSet.Tables)
    {
        Console.WriteLine(table.TableName);
    }
}


WIth the code above you can find the ecxact name that contains your input, so all youll have to do is designa a string function :)
 
Share this answer
 
v2
foreach(DataTable table in dataSet.Tables)
{
if(table.TableName=="tableName")
{
//do something
}

}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900