我的问题是,当我点击保存按钮时,只有txtEmail1
的值会保存在email
列中。
MySqlCommand cmd;
cmd.CommandText = "INSERT INTO email(Id,email)VALUES( @Id,@email)";
cmd.Parameters.AddWithValue("@Id", int.Parse(txtId.Text));
cmd.Parameters.AddWithValue("@email", txtEmail1.Text + "" + txtEmail2.Text);
cmd.ExecuteNonQuery();
答案 0 :(得分:0)
试试这个
string[] email = new string[2];
email[0] = txtEmail1.Text;
email[1] = txtEmail2.Text;
for (int i = 0; i < 2; i += 1)
{
MySqlCommand cmd;
cmd.CommandText = "INSERT INTO email(Id,email)VALUES( @Id,@email)";
cmd.Parameters.AddWithValue("@Id", int.Parse(txtId.Text));
cmd.Parameters.AddWithValue("@email",email[i]);
cmd.ExecuteNonQuery();
}