-3
我試圖獲取數據庫中表的總行數並將其顯示在文本框中。對於一些未知的原因,我的代碼將無法正常工作,而不是顯示其預期的結果SELECT COUNT(*)在文本框中不顯示任何內容
MySqlConnection con = new MySqlConnection(constring);
con.Open();
MySqlCommand comm = new MySqlCommand("SELECT COUNT(1) FROM addinv_table", con);
Int32 count = (Int32)comm.ExecuteScalar();
textBox1.Text = Convert.ToString(count);
編輯:目前通過做不同的方法解決我的問題。
MySqlCommand comm = new MySqlCommand("SELECT * FROM addinv_table");
MySqlDataAdapter ap = new MySqlDataAdapter(comm.CommandText, con);
DataSet ds = new DataSet();
ap.Fill(ds);
textBox1.Text = ds.Tables[0].Rows.Count.ToString();
它也適用於我們('出於某種未知的原因')與您發佈的信息。您可能想閱讀[如何調試小程序](https://ericlippert.com/2014/03/05/how-to-debug-small-programs/) –
當您運行相同的查詢時會得到什麼結果直接對數據庫通過工作臺或MySQL命令提示符? –
該文本框應該顯示31.我試着通過工作臺做它,它沒有問題。 – Kent