Keith McElroy
asked on
C# DROP table issue
ASHX C# problem with DROP TABLE
How can I resolve the error below
SqlCommand listtables = new SqlCommand("SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES" , conn);
using (SqlDataReader listtablesreader = listtables.ExecuteReader() )
{
while(listtablesreader.Rea d())
{
if(listtablesreader["TABLE _NAME"].To String().I ndexOf("go vfin_suppl ement_") > -1)
{
tabid = listtablesreader["TABLE_NA ME"].ToStr ing();
context.Response.Write(tab id);
SqlCommand droptab = new SqlCommand(@"
DROP TABLE [dbo].[" + tabid +@"]", conn);
droptab.ExecuteNonQuery();
}
}
}
Error:
There is already an open DataReader associated with this Command which must be closed first.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.InvalidOperationExc eption: There is already an open DataReader associated with this Command which must be closed firs
How can I resolve the error below
SqlCommand listtables = new SqlCommand("SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES"
using (SqlDataReader listtablesreader = listtables.ExecuteReader()
{
while(listtablesreader.Rea
{
if(listtablesreader["TABLE
{
tabid = listtablesreader["TABLE_NA
context.Response.Write(tab
SqlCommand droptab = new SqlCommand(@"
DROP TABLE [dbo].[" + tabid +@"]", conn);
droptab.ExecuteNonQuery();
}
}
}
Error:
There is already an open DataReader associated with this Command which must be closed first.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.InvalidOperationExc
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Never mind, it worked without that line,
ASKER
If I can solve this, then I can move forward with this little project.
Thanks!
Compiler Error Message: CS0103: The name 'CommandType' does not exist in the current context
Source Error:
Compiler Error Message: CS0103: The name 'CommandType' does not exist in the current context
Source Error:
Line 126:using (SqlCommand cmd = new SqlCommand("sp_RemoveTable
Line 127: {
Line 128: cmd.CommandType = CommandType.StoredProcedur
Line 129: cmd.ExecuteNonQuery();
Line 130: }
Source File: c:\inetpub\wwwroot\fin\ind