First, stop the Database Service and the SQL Server service.
// Retrieve all the table names in a database (table)
String strconn = "provider = Microsoft. Jet. oledb.4.0;" +
"Data Source =" + strpathname + ";" + "extended properties = Excel 8.0 ;";
String strfieldname = "";
Oledbconnection objconn = new oledbconnection (strconn );
Try
{
Objconn. open ();
}
Catch (exception ex)
{
M_strlasterror = ex. message;
Return "";
}
String strtablename = "";
If (strworkformname. Trim () = "") // if it is null, enter all worksheets
{// List all worksheet names in the Excel file
Strworkformname = "";
Datatable schematable = objconn. getoledbschematable (oledbschemaguid. Tables,
New object [] {null, "table "});
Foreach (datarow myrow in schematable. Rows)
{
Strtablename = myrow ["table_name"]. tostring ();
Strtablename = strtablename. Replace ("$ _", "$ ");
If (-1! = Strworkformname. indexof (strtablename ))
Continue;
If (strworkformname! = "")
Strworkformname + = ",";
Strworkformname + = strtablename;
}
}