コードで「無効な入力」が発生し続ける理由を誰かに教えてもらえますか?? データベースを何度かチェックしましたが、問題が見つからないようです。現在、正規化されたデータベースを使用しています。
間違ったコードを貼り付けたことに今気づきました
namespace MemorialSystem
{
public partial class Reservation : Form
{
SqlConnection con;
SqlCommand cmd;
SqlDataAdapter adapter;
SqlCommandBuilder cd;
DataSet ds;
public Reservation()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Form1 o = new Form1();
o.Show();
this.Hide();
}
private void Reservation_Load(object sender, EventArgs e)
{
con = new SqlConnection("Data Source=(local);Initial Catalog=Memorial_park;Integrated Security=True");
cmd = new SqlCommand("select * from Records", con);
adapter = new SqlDataAdapter(cmd);
cd = new SqlCommandBuilder(adapter);
ds = new DataSet();
}
private void button2_Click(object sender, EventArgs e)
{
con.Open();
try
{
if (textBox1.Text == "" || textBox2.Text == "" || textBox3.Text == "" || comboBox1.Text == "" || textBox8.Text == "" || dateTimePicker1.Value.ToString("yyyyMMdd HH:mm:ss") == "" || dateTimePicker2.Value.ToString("yyyyMMdd HH:mm:ss") == "" || textBox7.Text == "" || textBox5.Text == "" || dateTimePicker3.Value.ToString("yyyyMMdd HH:mm:ss") == "")
{
MessageBox.Show("Please input a value!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
else
{
if (MessageBox.Show("Are you sure you want to reserve this record?", "Reserve", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
cmd = new SqlCommand("insert into Records(NameofLotOwner, HomeAddress, TelNo, RelationDeceased, NameOfDeceased, Address, DateofBirth, DateofDeath, PlaceofDeath, CausefDeath, DateofInterment) values('" + textBox1.Text + "', '" + textBox2.Text + "', '" + textBox3.Text + "', '" + comboBox1.SelectedItem + "', '" + textBox8.Text + "', '" + dateTimePicker1.Value.ToString("yyyyMMdd HH:mm:ss") + "', '" + dateTimePicker2.Value.ToString("yyyyMMdd HH:mm:ss") + "', '" + textBox7.Text + "', '" + textBox5.Text + "', '" + dateTimePicker3.Value.ToString("yyyyMMdd HH:mm:ss") + "')", con);
cmd.ExecuteNonQuery();
MessageBox.Show("Your reservation has been made!", "Reserve", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
}
catch (Exception x)
{
MessageBox.Show("Invalid Input");
}
con.Close();
}
private void label16_Click(object sender, EventArgs e)
{
}
}
}