Create table using select statment using OLEDB in C# ASP.NET
993069Mar 14 2013 — edited Mar 24 2013Hi,
I am trying ctreate a table on oracle database from front end C# ASP.NET using OLEDB connection.
But I am not able to create table using select statment.
Can anyone please help me out with this and let me know how can I create a table using select statement. Select statment is having mote than one column which need to be inserted into new table.
I am trying below code but its not at all working and I guess I am doing it wrong.
OleDbCommand sql = new OleDbCommand("Select CUSTOMER_CITY, CUSTOMER_STATE, Region from Karen_Provided_Excel", con);
try
{
if (con.State == ConnectionState.Closed)
{
con.Open();
OleDbDataReader objReader;
objReader = sql.ExecuteReader();
//string strTemp = "Name Varchar(30), Address Varchar(30)";
OleDbCommand myCommand = new OleDbCommand();
myCommand.Connection = con;
myCommand.CommandText = "CREATE TABLE Abhi_Test_DotNet(" + objReader.ToString() + ")";
myCommand.ExecuteNonQuery();
Label1.Text = "Table Created Successfully";
}
}
catch (Exception ex)
{
Label1.Text = "<br />ERROR WITH TEST METHOD: " + ex;
}
finally
{
if (con.State == ConnectionState.Open)
{
con.Close();
}
} ;
Thanks in adavnce for your help.
Regards,
Abhishek