0
[在這裏輸入的形象描述] [1]如何使用COUNT函數有一個文本框在mysql中顯示在C#中的Visual Studio搜索結果
在我的代碼我使用一個DataGridView以顯示NIC號碼給客戶。然後,如果我們按計算按鈕,其他文本框必須填寫相關細節。一切都完成了。但伯爵仍然存在。我不能使用count命令,在mysql語法中顯示錯誤。
我想根據NIC號碼計數項目。非常感謝幫助。
private void dataGridView2_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
if (e.RowIndex >= 0)
{
DataGridViewRow row = this.dataGridView2.Rows[e.RowIndex];
textBox11.Text = row.Cells[1].Value.ToString();
}
}
private void button12_Click(object sender, EventArgs e)
{
if (textBox11.Text == null)
{
MessageBox.Show("Please select an Item");
}
else
{
con.Open();
string SelectQuery = "select * from cheque where national_id =" + (textBox11.Text);
MySqlCommand cmdDDDD = new MySqlCommand(SelectQuery, con);
mdr2 = cmdDDDD.ExecuteReader();
if (mdr2.Read())
{
textBox2.Text = mdr2.GetString("customer_name");
con.Close();
mdr2.Close();
Countmmm();
}
else
{
MessageBox.Show("No cheque from this ID");
con.Close();
mdr2.Close();
}
}
}
public void Countmmm()
{
con.Open();
string MysqlStringnow = "SELECT count(national_id) from cheque ='" + textBox11.Text + "'";
MySqlCommand mycqlcommandNow = new MySqlCommand(MysqlStringnow, con);
Int32 Rows_count = Convert.ToInt32(mycqlcommandNow.ExecuteScalar());
mycqlcommandNow.Dispose();
textBox4.Text = Rows_count.ToString();
con.Close();
}
[1]: https://i.stack.imgur.com/fS6D2.png
啊。我知道了。愚蠢的我。謝謝主席 –
你可以接受答案,如果沒關係 – nacho