private void btn_insert_item_Click(object sender, EventArgs e)
{
if(textBox9.Text != "" & textBox10.Text != "" & textBox11.Text != "")
{
DialogResult dialog = MessageBox.Show("Do you want to add item #" + textBox11.Text + "?",
"", MessageBoxButtons.YesNo);
if (dialog == DialogResult.Yes)
{
try
{
con.Open();
OracleCommand cmd = new OracleCommand("insert " +
"into table_a " +
"(order_date, " +
"order_no, " +
"item_name, " +
"item_no) " +
"values( " +
"sysdate, " +
"'" + textBox9.Text + "', " +
"'" + textBox10.Text + "', " +
"'" + textBox11.Text + "', " +
)", con);
cmd.CommandType = CommandType.Text;
OracleDataReader dr = cmd.ExecuteReader();
System.Data.DataTable dt = new System.Data.DataTable();
dt.Load(dr);
dataGridView1.DataSource = dt;
dr.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
con.Close();
MessageBox.Show("item has been added.");
}
}
if (dialog == DialogResult.No)
{
MessageBox.Show("No change has been made.");
button1_Click(sender, e);
}
}
}
这是我用于在table_a上插入单个项目#的代码。 textBox 9 = order_date,textBox10 = order_no,textBox11 = item_no。 如果我也有item_no的textBox12,那么如何在dataGridView上插入带有item_no的多行?如果我将item_no 1放在textBox11上,将10放在textBox12上,它应该插入10行,这些行具有相同的信息,但item_no从1到10。
请帮助。
答案 0 :(得分:0)
尝试使用textBox12.text作为计数器创建循环
例如:
for(int x=1;x<textBox12.text;x++)
{
//Your code.....
}