Hi,
I would like to resolve a logic. Little bit complicated for my.
I have four Textboxes (TextBox1, TextBox2, TextBox3, TexBox4) and three Buttons (Button1, button2, Button3).
What I need to do?
If TextBox1 and TextBox2 or TextBox1 and TextBox3 are filled by number more than 0 or minus 0 then click at Button3 (for example do Button3.PerformClick()). Otherwise don't activate Button3 and read the code above to save to my Database.
- private void Button1_Click(object sender, EventArgs e)
- {
- ////////////////////////////////////////////////////////////////////
- // The condition should be here. Its should pass ONLY these TextBoxes when are not filled
- //////////////////////////////////////////////////////////////////
- if (conn.State != ConnectionState.Open)
- conn.Open();
- SqlCommand comm1 = new SqlCommand();
- comm1.Connection = conn;
- SqlParameter data = new SqlParameter("@date", SqlDbType.Date);
- SqlParameter nord = new SqlParameter("@number", SqlDbType.VarChar);
- SqlParameter contas = new SqlParameter("@name", SqlDbType.VarChar);
- comm1.Parameters.Add(date);
- comm1.Parameters.Add(number);
- comm1.Parameters.Add(name);
- date.Value = TextBox1.Text;
- number.Value = TextBox2.Text;
- name.Value = TextBox3.Text;
- comm1.Connection = conn;
- comm1.CommandText = "insert into Table ([date],[number],[name])values(@date,@number,@name)";
- {
- if (MessageBox.Show("Are you sure to save?", "Saving window", MessageBoxButtons.YesNo) == DialogResult.Yes)
- {
- try
- {
- comm1.ExecuteNonQuery();
- SqlCommand cmd = conn.CreateCommand();
- cmd.CommandType = CommandType.Text;
- cmd.CommandText = "select [date],[number],[name] from Table";
- DataTable dt = new DataTable();
- SqlDataAdapter da = new SqlDataAdapter(cmd);
- da.Fill(dt);
- dgvTest.DataSource = dt;
- }
- finally
- {
- dgvTest.CurrentCell = dgvTest.Rows[dgvTest.Rows.Count - 2].Cells[0];
- }



Amit MohantyRank #112 · 20K reputationPosted Aug 19, 2019, 12:45 AM EDT
Nilesh SawardekarRank #648 · 3.7K reputationPosted Aug 16, 2019, 5:44 AM EDT
IsraelRank #1,223 · 1.5K reputationPosted Aug 16, 2019, 6:09 AM EDT
IsraelRank #1,223 · 1.5K reputationPosted Aug 16, 2019, 8:46 AM EDT
Nilesh SawardekarRank #648 · 3.7K reputationPosted Aug 17, 2019, 4:44 AM EDT
Happy Coding... :)