index > .NET Framework Data Access and Storage > oracleCommand error

oracleCommand error

someone..please tell me what is wrong with my code? i get an error when trying to open the connection. but in my second form i could connect to the database. i just dont get what is my mistake in here...

OracleCommand insert1 = new OracleCommand("insert into customer(cusnum, cusdt, cusid, cusstatus, cuscode, cusname, cussex) values (:p1, :p2, :p3, :p4, :p5, :p6, :p7)");

insert1.Connection = new OracleConnection(oracle);

OracleCommand insert2 = new OracleCommand("insert into request(reqnum, reqcode, reqname) values(:p8, :p9, :p10)");

insert2.Connection = new OracleConnection(oracle);

OracleParameter p1 = new OracleParameter(":p1", OracleType.Number);

p1.Value = txt1.Text;

OracleParameter p2 = new OracleParameter(":p2", OracleType.DateTime);

p2.Value = txt2.Text;

OracleParameter p3 = new OracleParameter(":p3", OracleType.VarChar);

p3.Value = txt3.Text;

OracleParameter p4 = new OracleParameter(":p4", OracleType.VarChar);

p4.Value = txt4.Text;

OracleParameter p5 = new OracleParameter(":p5", OracleType.VarChar);

p5.Value = txt5.Text;

OracleParameter p6 = new OracleParameter(":p6", OracleType.VarChar);

p6.Value = txt6.Text;

OracleParameter p7 = new OracleParameter(":p7", OracleType.VarChar);

p7.Value = txt7.Text;

OracleParameter p8 = new OracleParameter(":p8", OracleType.Number);

p8.Value = txt8.Text;

OracleParameter p9 = new OracleParameter(":p9", OracleType.VarChar);

p9.Value = txt9.Text;

OracleParameter p10 = new OracleParameter(":p10", OracleType.VarChar);

p10.Value = txt10.Text;

insert1.Parameters.Add(p1);

insert1.Parameters.Add(p2);

insert1.Parameters.Add(p3);

insert1.Parameters.Add(p4);

insert1.Parameters.Add(p5);

insert1.Parameters.Add(p6);

insert1.Parameters.Add(p7);

insert2.Parameters.Add(p8);

insert2.Parameters.Add(p9);

insert2.Parameters.Add(p10);

try

{

insert1.Connection.Open();

insert1.ExecuteNonQuery();

insert2.Connection.Open();

insert2.ExecuteNonQuery();

}

catch

{

MessageBox.Show("There is no connection to the Oracle database.");

}

finally{}

insert1.Connection.Close();

insert2.Connection.Close();

Xeleste

Hi,

Can you please post the error message being generated. Also try using only a single connection. Since as I noticed in your code both insert1 and insert2 have the same configuration in its connection object. YOu can do this:

OracleConnection conn = new OracleConnection(oracle);

OracleCommand insert1 = new OracleCommand("insert into customer(cusnum, cusdt, cusid, cusstatus, cuscode, cusname, cussex) values (:p1, :p2, :p3, :p4, :p5, :p6, :p7)");

insert1.Connection = conn;

OracleCommand insert2 = new OracleCommand("insert into request(reqnum, reqcode, reqname) values(:p8, :p9, :p10)");

insert2.Connection = conn;

and also please verify that you have closed the conneciton before opening it again. My advise would be to close it immediately after the execute is finish...

cheers,

Paul June A. Domag




Visit my Online Blog - http://webmag.mvps.org
Paul Domag
the error is that it could not connect to the Oracle database.
Xeleste
reply 3

You can use google to search for other answers

 

More Articles

• DataFormatString for DateTime column
• You help will be appreciated: Connection to DBF free table files
• parameter Array in Stored Procedure
• Closing classic ADO command object in VC#2005
• Some how the update command is not working.
• Sproc insert problem
• System.Security.AccessControl Namespace
• ADO.Net Performance
• IDbConnection.CreateCommand not intended to be used directly
• Parameter within WITH-Clause in MDX
Bookmark and Share
Welcome to Bokebb   New Update  
 

New Articles

• is it possible to interrupt fill method
• alter the value of a table
• DataTable Stripping time from DateTime
• streamreader+inserting/updating the rows
• Memory leak when using ODP.NET from http
• Design Issue: Multiple definitions of db
• Create table in code
• OraOLEDB.Oracle.1 provider is not regist
• Can't connect to database from web servi
• Expression Building - Access 2003
• System.Security.AccessControl Namespace
• Oracle Real Application Cluster Support
• my sql
• {"Object must implement IConvertibl
• ADO.Net-Insert, Update, and Deleting Rec

Hot Articles

• Problem with SqlBulkCopy when destinatio
• help: I need to view all the tables in a
• OleDbDataAdapter, Fill, Update, CommandB
• Data Access Strategy
• HELP!! writing sql in vb.net (ado.net)
• faster way of accessing CSV files
• Requesting a list of datasources in vs 2
• database search engine class library
• Selecting / Update records - Concurrancy
• Control.DoDragDrop and Exceptions
• How to Connect Microsoft Access database
• How to perform a case insensitive filter
• DataTable Stripping time from DateTime
• Combo Boxes and RecordSet
• DataSet or DataReader

Recommend Articles

• Desiging Data Access
• Internal .Net FrameWork Data Provider Er
• DataTable - Null Object Reference Error
• Issue in reading data from an Excel file
• T-SQL SELECT STATEMENTS
• Access to path to the database was denied
• database MDI application Dataset update
• ConfigurationManager.AppSettings not rea
• Using VB2005 Express to add new rows to
• Update SQL database...Please help
• SQLCommand insert not working for datase
• DOA2016.DLL
• Adding shortcut key to TabControl
• Retrieving @@Identity from Access databa
• GridView in Web Application Not Deleting