I have the following code that will add a new DataTable (excel sheet) to a DataSet. I am trying to do it by name so I can access the table like: ds.Tables["EmployeeNames"]
The problem is that if I do:
ds.Tables[0] - it works fine. The debugger shows the table as "EmployeeNames" and the TableName shows as "EmployeeNames".
But if I do: ds.Tables["EmployeeNames"]
I get a null.
Here is the code I am using:
How can I call this so I can access the database by name?
Thanks,
Tom
The problem is that if I do:
ds.Tables[0] - it works fine. The debugger shows the table as "EmployeeNames" and the TableName shows as "EmployeeNames".
But if I do: ds.Tables["EmployeeNames"]
I get a null.
Here is the code I am using:
Code:
public System.Data.DataSet GetWorksheet()
{
DataSet ds = new DataSet();
foreach (string ws in workSheetNames)
{
ds.Tables.Add(GetWorksheet(ws));
}
return ds;
}
public System.Data.DataTable GetWorksheet(string worksheetName)
{
OleDbConnection con = new System.Data.OleDb.OleDbConnection(connectionString);
OleDbDataAdapter cmd = new System.Data.OleDb.OleDbDataAdapter(
"select * from [" + worksheetName + "]", con);
con.Open();
System.Data.DataTable excelDataTable = new DataTable(worksheetName.Replace("$",""));
cmd.Fill(excelDataTable);
con.Close();
return excelDataTable;
}
How can I call this so I can access the database by name?
Thanks,
Tom