Hi - I'm updating an Oracle table with an empty string and getting the
error:
An unhandled exception of type 'System.Excepti on' occurred in
system.data.dll
Additional information: Parameter 'p1': No size set for variable length data
type: String.
The column is nullable and of type varchar2(50). I'm aware that I can store
DBNull.Value instead and Oracle won't complain, but, I was hoping to avoid
testing and converting for that condition. It seems the .NET class lib
should handle empty strings, no? There are times I'd like to throw the
dataset into a datagrid control and have the user have there way with it,
therefore, its not ideal to have to validate each string value on the
update.
Question 1: Is this a bug or am I doing something wrong?
Question 2: If its a bug, is there an elegant workaround?
Sample C# code is:
// create typed dataset (basic customer list: name, address, phone, etc.)
CustomerDS dsCustomer = new CustomerDS();
// create data adapter
OracleDataAdapt er daCustomers = new OracleDataAdapt er("SELECT * FROM
Customers", connectionStrin g);
// use command builder to create update, insert and delete commands based on
select
OracleCommandBu ilder cb = new OracleCommandBu ilder(daCustome rs);
// get some data
daCustomers.Fil l(dsCustomer.CU STOMERS)
// delete Middle Name, for example
dsCustomer.CUST OMERS.Rows[0]["MIDDLE_NAM E"] = "";
// store new dataset
daCustomers.Upd ate(dsCustomer, "Customers" );
// boom - get error (even though I put it in a try...catch block!)
error:
An unhandled exception of type 'System.Excepti on' occurred in
system.data.dll
Additional information: Parameter 'p1': No size set for variable length data
type: String.
The column is nullable and of type varchar2(50). I'm aware that I can store
DBNull.Value instead and Oracle won't complain, but, I was hoping to avoid
testing and converting for that condition. It seems the .NET class lib
should handle empty strings, no? There are times I'd like to throw the
dataset into a datagrid control and have the user have there way with it,
therefore, its not ideal to have to validate each string value on the
update.
Question 1: Is this a bug or am I doing something wrong?
Question 2: If its a bug, is there an elegant workaround?
Sample C# code is:
// create typed dataset (basic customer list: name, address, phone, etc.)
CustomerDS dsCustomer = new CustomerDS();
// create data adapter
OracleDataAdapt er daCustomers = new OracleDataAdapt er("SELECT * FROM
Customers", connectionStrin g);
// use command builder to create update, insert and delete commands based on
select
OracleCommandBu ilder cb = new OracleCommandBu ilder(daCustome rs);
// get some data
daCustomers.Fil l(dsCustomer.CU STOMERS)
// delete Middle Name, for example
dsCustomer.CUST OMERS.Rows[0]["MIDDLE_NAM E"] = "";
// store new dataset
daCustomers.Upd ate(dsCustomer, "Customers" );
// boom - get error (even though I put it in a try...catch block!)
Comment