Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

create and populate table in Oracle through C#

Status
Not open for further replies.

egil84

Programmer
Oct 19, 2003
13
'm trying to create table through this method. It connects to my database, it givs me a message that it was created but when I want to insert data through my form into the table, it says that the row/column/table doesn't exist. What am I doing wrong? Any help would be greatly appreciated. Thanks in advance.

Code:
//set up connection string
string connectionString = 
"Provider = OraOLEDB.Oracle;DataSource = csbank;User ID = system;Password = manager";
				
//create connection object and pass info  to it
OleDbConnection myOleDbConnection = 
new OleDbConnection(connectionString);

//string with the creation of table
string query = //got this down

//set up commands object and send the query 
OleDbCommand myOleDbCommand = new OleDbCommand(query,myOleDbConnection);

//create object so we can read the data (data reader)
OleDbDataReader datareader = null;

//open DB
myOleDbConnection.Open();

//execute the reader
datareader = myOleDbCommand.ExecuteReader();

//close reader
datareader.Close();
//close connection
myOleDbConnection.Close();	
myOleDbConnection.Dispose();
 
I didn' t see in your code :
myOleDbCommand.ExecuteNoQuery();
-obislavu-
 
I can't think of another way of doing this. I just want to connect to my Database and create a table. In the end of my code I have a message box telling me that my table was created, that's how I know it went through all my code. I have this is a try-catch and it doesn't give me any error. But when I go to my DataBase and try to view the table it says that the table was not created. How can it be possible? What's wrong here? Please help me!!![sadeyes]

Code:
//set up connection string
string connectionString = "Provider = OraOLEDB.Oracle;DataSource = csbank;User ID = system;Password = manager";
				
//create object and pass info  to it
OleDbConnection myOleDbConnection = 
new OleDbConnection(connectionString);

//string with the creation of table
string query = "//got the creation";

//set up commands and send the query 
OleDbCommand myOleDbCommand = 
new OleDbCommand(query,myOleDbConnection);

//open DB
myOleDbConnection.Open();
//set command to command coded in string query
myOleDbCommand.CommandText = query;

//close connection
myOleDbConnection.Close();	
myOleDbConnection.Dispose();

MessageBox.Show("Table created","Data Store Hotel");
 
Modify your code as I said before or something like that:

OleDbConnection myOleDbConnection = null;
OleDbCommand myOleDbCommand = null;
//set up connection string
string connectionString = "Provider = OraOLEDB.Oracle;DataSource = csbank;User ID = system;Password = manager";

try
{
//create object and pass info to it
myOleDbConnection = new OleDbConnection(connectionString);
myOleDbConnection.Open();

//string with the creation of table
string query = "//got the creation";

//set up commands and send the query
myOleDbCommand =new OleDbCommand();
myOleDbCommand.Connection = myOleDbConnection ;

//set command to command coded in string query
myOleDbCommand.CommandText = query;
myOleDbCommand.ExecuteNonQuery();

}
catch (Exception e)
{
MessageBox.Show(e.GetType() +e.Message();
}
finally
{
//close connection
if (myOleDbConnection!=null)
{
myOleDbConnection.Close();
myOleDbConnection.Dispose();
}
if (myOleDbCommand!=null)
myOleDbCommand.Dispose();

}

-obislavu-
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top