Kris
What type of object is being returned by dbSwitch.GetParameter? The .Add
method that takes an object tries to infer the type by the type of object.
-reggie
> -----Original Message-----
> From: Bekkers, Kris [mailto:Kris.Bekkers@stripped]
> Sent: Thursday, January 20, 2005 3:15 PM
> To: dotnet@stripped
> Subject: MysqlParameters and connector 1.03
>
> All,
>
> I believe I found a little problem. (But I could be mistaking).
>
> The table definition
> CREATE TABLE `tbl_talen` (
> `LanguageId` varchar(75) NOT NULL default '',
> PRIMARY KEY (`LanguageId `)
> ) ENGINE=InnoDB DEFAULT CHARSET=latin1
>
> The situation:
>
> ... creating the command type (ommited ....)
>
> cmd.CommandType = CommandType.Text
> cmd.CommandText = "Select count(*) as TotalFound from {0} where LanguageId
> = ?searchVal";
> cmd.Parameters.Add(dbSwitch.GetParameter("?searchVal",
> m_oEditedObject.Name));
>
> Executing:
> if ((Convert.ToInt32(cmd.ExecuteScalar())) > 0)
> {
> bRetval = true;
> break;
> }
>
> This gives me the following error:
> "Input string was not in a correct format."
> And some of the stack-trace included also:
> System.FormatException: Input string was not in a correct format.
> at System.Number.ParseDecimal(String s, NumberStyles style,
> NumberFormatInfo info)
> at System.Decimal.Parse(String s, NumberStyles style, IFormatProvider
> provider)
> at System.Convert.ToDecimal(String value, IFormatProvider provider)
> at System.String.System.IConvertible.ToDecimal(IFormatProvider
> provider)
> at System.Convert.ToDecimal(Object value)
> at MySql.Data.Types.MySqlDecimal.Serialize(PacketWriter writer, Boolean
> binary, Object value, Int32 length) in
> C:\_Net\_MySqlDriver\MySqlClient\Types\MySqlDecimal.cs:line 56
> at MySql.Data.MySqlClient.MySqlParameter.Serialize(PacketWriter writer,
> Boolean binary) in C:\_Net\_MySqlDriver\MySqlClient\parameter.cs:line 307
> at MySql.Data.MySqlClient.MySqlCommand.SerializeParameter(PacketWriter
> writer, String parmName) in
> C:\_Net\_MySqlDriver\MySqlClient\command.cs:line 504
> at MySql.Data.MySqlClient.MySqlCommand.PrepareSqlBuffers(String sql) in
> C:\_Net\_MySqlDriver\MySqlClient\command.cs:line 557
> at MySql.Data.MySqlClient.MySqlCommand.ExecuteReader(CommandBehavior
> behavior) in C:\_Net\_MySqlDriver\MySqlClient\command.cs:line 433
> at MySql.Data.MySqlClient.MySqlCommand.ExecuteReader() in
> C:\_Net\_MySqlDriver\MySqlClient\command.cs:line 408
> at MySql.Data.MySqlClient.MySqlCommand.ExecuteScalar() in
> C:\_Net\_MySqlDriver\MySqlClient\command.cs:line 452
> at
> FraClaDoc.Client.CommonUI.Maintenance.Base.maintain_Languages.HasData() in
> C:\_Net\Projects\FraClaDoc\Sources\FraClaDoc.Client.CommonUI\FraClaDoc.Cli
> ent.CommonUI\Maintenance\Base\maintain_Languages.cs:line 267
> at
> FraClaDoc.PresLayer.Forms.Maintenance.Base.MasterDataBase.m_iMasterData_it
> emschanging(Object sender, ItemsChanged itemsChanged) in
> C:\_Net\_Components\FraClaDoc\FraClaDoc.PresLayer\Forms\Maintenance\Base\M
> asterDataBase.cs:line 768
> at
> FraClaDoc.PresLayer.Forms.Bases.Controls.MasterDataControl.pRaiseChangedEv
> ent(Boolean Changed) in
> C:\_Net\_Components\FraClaDoc\FraClaDoc.PresLayer\Forms\Bases\Controls\Mas
> terDataControl.cs:line 147
> at
> FraClaDoc.Client.CommonUI.Maintenance.Base.maintain_Languages.pSetLanguage
> () in
> C:\_Net\Projects\FraClaDoc\Sources\FraClaDoc.Client.CommonUI\FraClaDoc.Cli
> ent.CommonUI\Maintenance\Base\maintain_Languages.cs:line 156
>
>
>
> The error is raised in this procedure: It is trying to convert my varchar
> parameter into a decimal which obviously will throw the error.
> internal override void Serialize(PacketWriter writer, bool
> binary, object value, int length)
> {
> Decimal v = Convert.ToDecimal( value );
> if (binary)
> {
> writer.WriteLenString(
v.ToString(numberFormat) );
> }
> else
> {
> writer.WriteLenString(
v.ToString(numberFormat) );
> }
> }
>
> The same procedure taking an int32 as a parameter (with a database field
> defined as an integer) however works fine and gives no errors.
> This makes me think that I should give the "type" of the parameter upon
> construction of that paramete.
> However, is this needed (by design) or implemented by the mysqlconnector?
>
> Thxs
>
> Kris
>
>
>
>
>
> **************************************************************************
> **
> Disclaimer:
> This electronic transmission and any files attached to it are strictly
> confidential and intended solely for the addressee. If you are not
> the intended addressee, you must not disclose, copy or take any
> action in reliance of this transmission. If you have received this
> transmission in error, please notify the sender by return and delete
> the transmission. Although the sender endeavors to maintain a
> computer virus free network, the sender does not warrant that this
> transmission is virus-free and will not be liable for any damages
> resulting from any virus transmitted.
> Thank You.
> **************************************************************************
> **
>
> --
> MySQL on .NET Mailing List
> For list archives: http://lists.mysql.com/dotnet
> To unsubscribe: http://lists.mysql.com/dotnet?unsub=1