-2
我正在做這個代碼列表視圖到數據庫我想保存所有的列,它會保存,但它會在每一行顯示一個消息框。有人可以幫我解決這個問題,我想只顯示一個消息框,當按鈕的點擊。 因此,這裏是我的代碼C#消息框連續多次顯示
foreach (ListViewItem li in listView1.Items)
{
string condense = "datasource=localhost;port=3306;username=root;password=''";
string milk = "insert into cashier.sales(Cashier,Orders,Quantity,Size,Price,Date) values ('" + this.cashier.Text + "','" + li.SubItems[0].Text + "','" + li.SubItems[1].Text + "','" + li.SubItems[2].Text + "','" + li.SubItems[3].Text + "','" + this.dateTimePicker1.Value + "');";
MySqlConnection conDatabase = new MySqlConnection(condense);
MySqlCommand cmdDatabase = new MySqlCommand(milk, conDatabase);
MySqlDataReader myReader;
if (string.IsNullOrEmpty(cashier.Text))
{
MessageBox.Show("Please fill the Notes. ", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
else
{
conDatabase.Open();
myReader = cmdDatabase.ExecuteReader();
MessageBox.Show("Order has been added successfully ", "Order!", MessageBoxButtons.OK, MessageBoxIcon.Information);
total.Text = "";
amount.Text = "";
change.Text = "";
while (myReader.Read())
{
}
}
}
的
MessageBox
外放foreach循環您messagebox.show之外。 – EpicKip現在你說每行顯示消息框... – EpicKip
omg。非常感謝。 –