Re: Using OleDBParameter in a simple UPDATE statement

From: Patrick Questembert (patrickq_at_hotmail.com)
Date: 10/18/04


Date: Sun, 17 Oct 2004 23:27:20 -0400

When I do: "DESCRIBE MyTable;" it shows the column I am targetting as being
of the type "INT(11)" (I guess 11 means MySQL needs 11 bytes to store it).
Furthermore, when I do a "SELECT val2 FROM MyTable;" and print out the type
of the first column (myReader[0].GetType()), I get "System.Int32".

This is supposed to map to OleDbType.Integer - which fails.
Just in case, I also tried OleDbType.SmallInt and OleDbType.BigInt.

Nada - all yield the illuminating E_ABORT error ...

Am I expecting too much to be able to read and update a simple signed
integer value :-)?
And I think some kind of useful hint(s) in the error return would have been
nice.

Here is again the minimal code showing the error:

     DatabaseConnection = new OleDbConnection("Provider=MySQLProv;Data
Source=WebReader; User ID=root;");
    DatabaseConnection.Open();
    OleDbParameter p = catCMD.CreateParameter();
    p.ParameterName = "val2";
    p.OleDbType = OleDbType.Integer;
    p.Value = System.Convert.ToInt32(123);
    // I assume no need to set p.Size
    catCMD.Parameters.Add(p);
    catCMD.CommandText = "INSERT INTO t2 (val1,val2) VALUES (8,?);";
    catCMD.ExecuteNonQuery();

Any ideas?

By the way: I just spend a couple of hours until I figured out that
apparently the SQL commands via the .NET OleDb objects w/MySQL are required
to have the reserved keywords in uppercase ... needs to be "SELECT etc", not
"select etc" (which generates an exception, with the same E_ABORT code). I
certainly didn't expect nor read anything about it anywhere, but apparently
it is so ...

Thanks,
Patrick

"Sahil Malik" <contactmethrumyblog@nospam.com> wrote in message
news:%23EUMU0ItEHA.1452@TK2MSFTNGP11.phx.gbl...
> Position is not all that matters, the name matters too - particularly for
> stored procs. Actually that is specific to the underlying database you are
> using.
>
> Anyway, another thing databases are rather picky about at times are the
> specific data type.
>
> Even the .NET common types donot map one on one to Sql types, and that's a
> pain on the booty 9 times out of 10, but a simple data mapping function
> gets over that. Also you might already know this, but an int to one
> platform might be not an int some other platform (# of bits might differ).
>
> - Sahil Malik
> You can reach me thru my blog -
> http://www.dotnetjunkies.com/weblog/sahilmalik
>
>
> "Patrick Questembert" <patrickq@hotmail.com> wrote in message
> news:1098018108.2+w0+8WqA9tQTI6OVuWjqg@teranews...
>>I am afraid I am not understanding at all how OleDbParameters work (I am
>>new to SQL) ... the simple code below fails with E_ABORT:
>>
>> OleDbParameter p = catCMD.CreateParameter();
>> p.ParameterName = "val2";
>> p.OleDbType = OleDbType.Integer;
>> p.Value = 8;
>> catCMD.Parameters.Add(p);
>> catCMD.CommandText = "INSERT INTO MyTable (val1,val2) VALUES (5,?);"
>> catCMD.ExecuteNonQuery();
>>
>> [Not sure what's the role of the ParameterName actually, I would have
>> thought that all that matters is the position of the parameter in the
>> params collection, as matching the "?" I am targetting.]
>>
>> Help :-)!
>>
>> Patrick
>>
>> PS: this is with MySQL 4.1 as the database
>>
>
>



Relevant Pages

  • Re: Moving from C++ to VC++
    ... If it is the longest integer. ... platform, I want the longest integer type ... Now /I/ would like to have 'int' being the ... Adhering to what computing standards' intention ...
    (microsoft.public.vc.language)
  • Re: I2C bus implementation (for MPC82xx)
    ... > PowerMac (see the patches that just went in rewriting the PowerMac i2c ... > smbus API, but then, do you really want to use an existing i2c driver? ... For the resources I have used platform definition. ... +static int ...
    (Linux-Kernel)
  • Re: Binary-mode i/o, width of char, endianness
    ... where should fread put this? ... >>into a long int. ... > Consider a platform with 11-bit bytes. ... type 'char' interchangably with 'an int that is one _byte_ big'. ...
    (comp.lang.c)
  • Re: Type of argc
    ... So did removing implicit int, but it improved the language nevertheless. ... Clever programmer #2 has to port the program to platform #2 which has a compiler not up to date. ... And that this C implementation could provide a non-standard way to access all the parameters, such as making argv a NULL-terminated string of pointers to char. ...
    (comp.std.c)