2 つのテキスト ボックスと 2 つの送信ボタンがあります。各ボタンはテキストボックス内の情報を送信します。両方のテキストボックスを一度に送信する送信ボタンが 1 つ必要です。問題は、1 つのテキスト ボックスが空の場合、データが空のデータで上書きされることです。テキストボックスに何かがある場合にのみ情報を送信したいと思います。いくつかの疑似コード コードが役立つ場合があります。
- textbox1 が空の場合は何もせず、textbox2 にデータがある場合はデータベースを更新します。
- textbox1 にデータがある場合は更新し、textbox2 が空の場合は textbox2 を更新しません。
これが私のコードです。私が言っていることが理にかなっていることを願っています。
protected void Button3_Click(object sender, EventArgs e)
{
SqlConnection conns = new SqlConnection(ConfigurationManager.ConnectionStrings["TestDBConnectionString1"].ConnectionString);
SqlCommand cmd = new SqlCommand("UPDATE test SET SitUps = @SitUps WHERE (Id = @Id)", conns);
cmd.CommandType = CommandType.Text;
Label IdL = ((Label)FormView1.FindControl("IdLabel"));
cmd.Parameters.AddWithValue("@Id", IdL.Text);
cmd.Parameters.AddWithValue("@SitUps", Sits.Text);
conns.Open();
cmd.ExecuteNonQuery();
Label17.Text = "Successfully Submitted Sit-Ups!";
}
protected void Button4_Click(object sender, EventArgs e)
{
SqlConnection conns = new SqlConnection(ConfigurationManager.ConnectionStrings["TestDBConnectionString1"].ConnectionString);
SqlCommand cmd = new SqlCommand("UPDATE test SET pushUps = @pushUps WHERE (Id = @Id)", conns);
cmd.CommandType = CommandType.Text;
Label IdL = ((Label)FormView1.FindControl("IdLabel"));
cmd.Parameters.AddWithValue("@Id", IdL.Text);
cmd.Parameters.AddWithValue("@pushUps", Push.Text);
conns.Open();
cmd.ExecuteNonQuery();
Label18.Text = "Successfully Submitted Push-Ups!";
}