protected void submitBtn_Click(object sender, EventArgs e)
{
SqlConnection connect = new SqlConnection("Data Source=THEBEAST;Initial Catalog=newregDB;Integrated Security=True;Pooling=False");
{
if (parentRadBtn.Checked)
{
SqlCommand pa = new SqlCommand("INSERT INTO parent(parentID, firstname, surname, postcode, telephone, email, password) VALUES (@parentID, @firstname, @surname, @postcode, @telephone, @email, @password)", connect);
pa.Parameters.AddWithValue("@parentID", userBox.Text);
pa.Parameters.AddWithValue("@firstname", firstNameBox.Text);
pa.Parameters.AddWithValue("@surname", surnameBox.Text);
pa.Parameters.AddWithValue("@postcode", postcodeBox.Text);
pa.Parameters.AddWithValue("@telephone", teleBox.Text);
pa.Parameters.AddWithValue("@email", emailBox.Text);
pa.Parameters.AddWithValue("@password", passwordBox.Text);
connect.Open();
pa.ExecuteNonQuery();
connect.Close();
if (IsPostBack)
{
userBox.Text = "";
firstNameBox.Text = "";
surnameBox.Text = "";
postcodeBox.Text = "";
teleBox.Text = "";
emailBox.Text = "";
passwordBox.Text = "";
}
else if (childRadBtn.Checked)
{
SqlCommand ca = new SqlCommand("INSERT INTO children(childID, firstname, dob, gender, password) VALUES (@childID, @firstname, @dob, @gender, @password)", connect);
ca.Parameters.AddWithValue("@childID", userBox.Text);
ca.Parameters.AddWithValue("@firstname", firstNameBox.Text);
ca.Parameters.AddWithValue("@dob", dayDobList.Text + monthDobList.Text + yearDobList.Text);
ca.Parameters.AddWithValue("@gender", genderList.Text);
ca.Parameters.AddWithValue("@password", passwordBox.Text);
connect.Open();
ca.ExecuteNonQuery();
connect.Close();
if (IsPostBack)
{
userBox.Text = "";
firstNameBox.Text = "";
dayDobList.Text = "";
monthDobList.Text = "";
yearDobList.Text = "";
genderList.Text = "";
passwordBox.Text = "";
}
}
}
}
}
}
こんにちはすべて動作していない場合は、場合、ステートメントが正常に
私は他の質問で周りを見回しましたが、それらのどれも私の問題を正確に一致していないか、C#ではありません。私はVisual Studioを使用してC#でasp.net Webアプリケーションを作成しています。私は親子のために記入するフォームのページを持っています(ラジオボタンを使って完成しました)。親ラジオボタンを選択し、送信ボタンを使用してデータベースの親テーブルに情報を送信すると、正常に動作します。子ラジオボタンで同じことをしようとすると、自分のデータベースの子テーブルに情報が格納されません。
if(parentRadBtn.Checked)ステートメントをコメントアウトし、 'else if(childRadBtn.Checked)'をスタンドアロンのifステートメントにして、正しく動作するようにしました(子テーブルに情報を格納しています)。これは、私がアプリケーションが 'else if(childRadBtn.Checked)'ステートメントに達していないと信じていました。そして、私はそれをうまく動作させることができません。上記の私のコードを見れば、誰かが私のif文でどこが間違っているのか教えてくれますか?前もって感謝します!
。私はこれを実証するために142行が必要であることを非常に疑う。私は、データベース側が関連性があるとは思っていません。可能な限りすべてを減らしてください。 –
「私の正確な問題にマッチするものも、C#にもないもの」「そのトリックは、それらの問題とその解決方法を理解し、その知識を自分の問題に適用することです。問題の正確なマッチを見つけることはほとんどありません。 – Amy
これは、if文がどこにあるのか、どこに問題があるのか、Jonを指摘してくれたため、送信ボタンのクリックイベントだけを表示するようにコードを編集しました。 – ACostea