從MySQL中的表中讀取值時出現問題,是索引值,無論如何我都無法讀取值。我得到的是0的初始化值我沒有得到任何錯誤,因爲它返回0,如果我在數據庫中運行查詢,它會得到正確的值。我試圖使用executeScalar(),但結果相同。從mysql讀取int的C#
MySqlConnection conn = new MySqlConnection(MyConString);
ulong ukey=0;
try
{
string sql_users2 = "SELECT `key` FROM `permuser` WHERE `user` = '" + myuser + "' AND `code` = '" + mycode + "'";
MySqlCommand cmdSel2 = new MySqlCommand(sql_users2, conn);
conn.Open();
MySqlDataReader dr2 = cmdSel2.ExecuteReader();
dr2.Read();
ukey = dr2.GetUInt64(dr2.GetOrdinal("key"));
// MessageBox.Show("Sorry " + myuser + " already have access to " + mycode + ",\nIf this is an extension, search for the user which key is " + ukey + " and edit the end date.", "Duplicate User Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
dr2.Close();
dr2.Dispose();
}
catch (MySqlException ex) //catch 2
{
MessageBox.Show("catch ukey\nCan't connect to database\n" + ex.ToString());
}
conn.Close();
conn.Dispose();
什麼是錯誤?你從讀者那裏得到什麼價值? – David
定義「不能讀取數值」:返回什麼?有什麼錯誤?你可以附加一個真實的例子(即「如果數據是這樣的,代碼應該返回一個蘋果,而是返回一個香蕉」)? – Alex
我假設你已經使用了調試器,結果是什麼?順便說一句,使用[參數](http://www.devart.com/dotconnect/mysql/docs/Devart.Data.MySql~Devart.Data.MySql.MySqlParameter.html)! –