Robert Vando Butarbutar Robert Vando Butarbutar - 3 months ago 8
C# Question

Textbox throwing an error when empty

I just try to make

if (txtNo.Text != "" || txtName.Text != "" || txtAddress.Text != "")
{
MessageBox.Show("Please Fill Textbox");
}


enter image description here

I just click update with not value in textbox.

I just make clear when the textbox in the user press the update button, then the warning messages are displayed so that the user recharges. Without being subject to error or out of the program, I am using SQL SERVER to save data.

Answer

Change your button code like this.

private void btnUpdate_Click(object sender, EventArgs e)
        {
            if (txtNo.Text == "" || txtName.Text == "" || txtAddress.Text == "")
            {
                MessageBox.Show("Please Fill TextBox");
                return;
            }
            SqlCommand CMD = new SqlCommand(UPDATE...
            Connection.Buka.....();
            CMD.ExecuteNonQuery();
            MessageBox.Show(....)
            Connection.Tutu.....();
        }