dizuane
September 15th, 2008, 09:52 PM
I'm trying to force a table to be deleted. In this case, a table is linked to another and thus when I try to DROP the table, an exception is thrown (oledbexception) and the table isn't dropped. How can I force it to delete the table? This is, actually, using the Northwind.mdb database (I'm learning). In the database, there is a table named "Order Details." However, I want it to be "OrderDetails" (no space). In order to accomplish this, the code first checks to see if any tables have a space in them and if so it combines the two words and drops ths space. That parts easy, and done. But when the new table is created, I want to drop the old one (in this case, "Order Details"). Suggestions?
foreach (DataRow row in tables.Rows)
{
//If the result is greater than 0 (i.e. there are spaces)...
if (row[2].ToString().IndexOf(" ") >= 0)
{
//Strip and save
string tempOld = row[2].ToString();
string tempNew = row[2].ToString().Replace(" ", "");
string sqlCommand = "SELECT * INTO " + tempNew + " FROM [" +
tempOld + "]";
command = new OleDbCommand(sqlCommand, con);
OleDbDataReader tempReader = command.ExecuteReader();
sqlCommand = "DROP TABLE [" + tempOld + "]";
command = new OleDbCommand(sqlCommand, con);
try
{
tempReader = command.ExecuteReader();
}
catch (OleDbException ode)
{
}
foreach (DataRow row in tables.Rows)
{
//If the result is greater than 0 (i.e. there are spaces)...
if (row[2].ToString().IndexOf(" ") >= 0)
{
//Strip and save
string tempOld = row[2].ToString();
string tempNew = row[2].ToString().Replace(" ", "");
string sqlCommand = "SELECT * INTO " + tempNew + " FROM [" +
tempOld + "]";
command = new OleDbCommand(sqlCommand, con);
OleDbDataReader tempReader = command.ExecuteReader();
sqlCommand = "DROP TABLE [" + tempOld + "]";
command = new OleDbCommand(sqlCommand, con);
try
{
tempReader = command.ExecuteReader();
}
catch (OleDbException ode)
{
}