HighTechTalks DotNet Forums  

OdbcParameter - Unable to a database update

Dotnet Framework (ODBC.net) microsoft.public.dotnet.framework.odbcnet


Discuss OdbcParameter - Unable to a database update in the Dotnet Framework (ODBC.net) forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
OdbcParameter - fail database update
 
Posts: n/a

Default OdbcParameter - Unable to a database update - 06-16-2009 , 08:01 AM






I have created an ODBCDataAdapter and then created a UpdateCommand using the
sql statement "update tab_author set auth_id = ? where auth_num = ?"

For the updatecommand I have created 2 new paramaters

adapter.UpdateCommand.Parameters.Add("@auth_id", OdbcType.Char, 3, "auth_id");

and then

OdbcParameter param = new OdbcParameter();
param.DbType = DbType.Int32;
param.Size = 10;
param.ParameterName = "@auth_num";
param.SourceVersion = DataRowVersion.Original;
param.SourceColumn = "auth_num";
adapter.UpdateCommand.Parameters.Add(param);

This paramater refers to a serial key in a database. When I do an update I
get the following error message "Invalid string or buffer length". If I
don't include the serial paramater and instead hard code the serial into the
sql statement, the update works.

I can't do this because I believe that the DBConcurrencyException error will
not be thrown when doing updates if I don't have the serial field as a
paramater..

So how do I created a OdbcParameter that refers to a serial key in a database.

Reply With Quote
  #2  
Old   
LowLevelAlbert
 
Posts: n/a

Default RE: OdbcParameter - Unable to a database update - 06-18-2009 , 09:12 PM






For DbType.Int32 you shouldn't touch param.Size. After initializing the
param leave it and that should fix your problem.

"OdbcParameter - fail database update" wrote:

Quote:
I have created an ODBCDataAdapter and then created a UpdateCommand using the
sql statement "update tab_author set auth_id = ? where auth_num = ?"

For the updatecommand I have created 2 new paramaters

adapter.UpdateCommand.Parameters.Add("@auth_id", OdbcType.Char, 3, "auth_id");

and then

OdbcParameter param = new OdbcParameter();
param.DbType = DbType.Int32;
param.Size = 10;
param.ParameterName = "@auth_num";
param.SourceVersion = DataRowVersion.Original;
param.SourceColumn = "auth_num";
adapter.UpdateCommand.Parameters.Add(param);

This paramater refers to a serial key in a database. When I do an update I
get the following error message "Invalid string or buffer length". If I
don't include the serial paramater and instead hard code the serial into the
sql statement, the update works.

I can't do this because I believe that the DBConcurrencyException error will
not be thrown when doing updates if I don't have the serial field as a
paramater..

So how do I created a OdbcParameter that refers to a serial key in a database.

Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.