I wanted to add an if statement to this code that says..
IF i click this button , it will check if the ListU.SelectedValue is empty or not , and if it is empty , a messagebox saying "please pick a name before continuing" , and if it is not empty , the code then runs.
how do i do that?
this is the code for the button click. (i know , my code needs some parameter , we can ignore that for the moment)
private void button4_Click(object sender, EventArgs e){ //update code// SqlConnection conn = new SqlConnection(); conn.ConnectionString = "Data Source=PEWPEWDIEPIE\\SQLEXPRESS;Initial Catalog=master;Integrated Security=True"; conn.Open(); SqlDataAdapter daCount = new SqlDataAdapter("select iCount from ComDet where cName = @cName", conn); daCount.SelectCommand.Parameters.Add("@cName", SqlDbType.VarChar).Value = ListU.SelectedValue; DataTable dtC = new DataTable(); daCount.Fill(dtC); DataRow firstRow = dtC.Rows[0]; string x = firstRow["iCount"].ToString(); int y = Int32.Parse(x); int z = y + 1; SqlCommand cmdC = conn.CreateCommand(); cmdC.CommandText = "Update ComDet set iCount = " + z + ", ViewTime = '" + lblTime.Text + "', LastView = '" + txtUser2.Text + "' Where cName = '" + ListU.SelectedValue.ToString() + "'"; cmdC.ExecuteNonQuery(); conn.Close(); var ufdet = new UserFullDetail(ListU.SelectedValue.ToString()); ufdet.ShowDialog();}
ليست هناك تعليقات:
إرسال تعليق