Parameterized query that returns TEXT column(s) always returns zero for INT columns

我们两清 提交于 2020-01-05 08:24:21

问题


Problemt with C# mySQL ODBC My table

CREATE TABLE `account` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`fbid` varchar(30) NOT NULL,
`fbname` varchar(80) NOT NULL,
`datecreate` datetime NOT NULL,
`ipcreate` varchar(20) NOT NULL,
`datelogin` datetime NOT NULL,
`iplogin` varchar(20) NOT NULL,
`xstatus` int(2) NOT NULL,
`xverstion` int(5) NOT NULL,
`xdata` text NOT NULL,
`xitem` text NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=1 DEFAULT CHARSET=utf8

My procedure:

CREATE PROCEDURE `VVVVV_getUserByFbId`(fbid2 varchar(30))
BEGIN
SELECT * from vvvvv_account where vvvvv_account.fbid=fbid2 LIMIT 1;
END

fbid2 is parameter (=408301576730032) in C# code

OdbcConnection connection = new OdbcConnection(constr);
            OdbcCommand cmd;           
            DataTable dt = new DataTable();
            try
            {

                OpenConnection(connection);

                cmd = new OdbcCommand("{call VVVVV_getUserByFbId(?)}", connection);
cmd.Parameters.AddWithValue("@fbid2", "408301576730032");
                cmd.CommandType = CommandType.StoredProcedure;

                OdbcDataAdapter da = new OdbcDataAdapter(cmd);
                da.Fill(dt);
                da.Dispose();
            }
            catch (Exception ex)
            {

            }
            finally
            {
                CloseConnection(connection);
            }
            return dt;

output in C# dt.Rows[0]["id"] always = 0 Not Ok dt.Rows[0]["fbname"] = "ABC" OK

means I can still get data from database normal. But int column alway = 0, varchar, datetime colume is ok;

But if I change the procedure to:

BEGIN
    select * from account where account.fbid='408301576730032' LIMIT 1;
END

In C# "{call VVVVV_getUserByFbId()}" -> id field = 3903

If no parameter (fbid2) or no text fied (xdata, xitem) -> id, xstatus (int fields) return normal. But if an parameter is passed or select xdata -> id (int fields) always = 0;

enter image description here


回答1:


You have encountered a verified bug in MySQL Connector/ODBC, reported here:

https://bugs.mysql.com/bug.php?id=97191

Since you are using C# you may want to see if MySQL Connector/NET works better for your application.




回答2:


Please try to convert the returning value to int as follows.

int x = System.Convert.ToInt32(dt.Rows[0]["id"]);

The issue might be that MySql int is not mapping to C# int.



来源:https://stackoverflow.com/questions/58459844/parameterized-query-that-returns-text-columns-always-returns-zero-for-int-colu

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!