Note that there are some explanatory texts on larger screens.

plurals
  1. POReading MySQL Int(10) value in C# doesn't work
    primarykey
    data
    text
    <p>I'm trying to connect to mysql from C# WinForms program. Everything seems to be working fine, i get 99% of column values just fine just one <code>int</code> column doesn't want to return proper value:</p> <pre><code> public static void getFromMySqlAndInsertIntoSql() { const string preparedCommand = @" select * from agreements"; using (var varConnection = Locale.sqlConnectOneTimeMySql(Locale.sqlDataConnectionDetailsMySQL)) using (var sqlQuery = new MySqlCommand(preparedCommand, varConnection)) { using (var sqlQueryResult = sqlQuery.ExecuteReader()) while (sqlQueryResult.Read()) { int agr_id = sqlQueryResult["agr_id"] is int ? (int)sqlQueryResult["agr_id"] : int.MinValue; string agr_idTest = sqlQueryResult["agr_id"].ToString(); string agr_fname = sqlQueryResult["agr_fname"].ToString(); int agr_stocks_count = sqlQueryResult["agr_stocks_count"] is int ? (int)sqlQueryResult["agr_stocks_count"] : int.MinValue; MessageBox.Show(agr_id.ToString(), agr_idTest); } } } } </code></pre> <p><code>agr_id</code> always returns int.MinValue, but <code>agr_idTest</code> it returns proper string. <code>int</code> value for <code>agr_stocks_count</code> returns int properly so it doesn't seem to be the problem with code. </p> <p>The only difference I can find in the MySQL table between first int column and the other is:</p> <pre><code>Field Type Collation Attributes Null Default Extra agr_id int(10) UNSIGNED No None AUTO_INCREMENT agr_stocks_count int(11) No None </code></pre> <p>Does anyone have explanation?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload