C#消息框连续显示多个
C# Message box multiple display in a row
我正在为数据库的列表视图执行此代码我想保存所有列,它保存但它在每一行中显示一个消息框。有人可以帮我解决这个问题吗?我只想在单击按钮时显示一个消息框。
所以这是我的代码
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 (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();
total.Text = "";
amount.Text = "";
change.Text = "";
while (myReader.Read())
{
}
}
}
MessageBox.Show("Orders has been added successfully ", "Order!", MessageBoxButtons.OK, MessageBoxIcon.Information);
我正在为数据库的列表视图执行此代码我想保存所有列,它保存但它在每一行中显示一个消息框。有人可以帮我解决这个问题吗?我只想在单击按钮时显示一个消息框。 所以这是我的代码
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 (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();
total.Text = "";
amount.Text = "";
change.Text = "";
while (myReader.Read())
{
}
}
}
MessageBox.Show("Orders has been added successfully ", "Order!", MessageBoxButtons.OK, MessageBoxIcon.Information);