Durga Velusamy

Durga Velusamy

  • NA
  • 318
  • 114.4k

windows Application with sql server 2008

Mar 23 2015 2:32 AM
i need example program code which includes windows form and database code. 
 
i want to know how to give if condition with database connectivity. i have code like this

 private void button1_Click(object sender, EventArgs e)
        {
             
            {
                SqlConnection con = new SqlConnection(@"server=CSE-PC; integrated security=true; Database=Bas");
                con.Open();
                SqlCommand cmd1 = new SqlCommand("insert into devi Values('" + comboBox1.Text + "',+'" + comboBox2
                    .Text + "','" + comboBox3.Text + "','" + comboBox4.Text + "','" + comboBox5.Text + "','" + comboBox6.Text + "','" + comboBox7.Text + "')", con);

                cmd1.ExecuteNonQuery();          hera, i need to give if condition for null. i.e . if box is empty it does not store. it need to show message as MessageBox.Show("doesnot store null value");
                con.Close();
                MessageBox.Show("Added Successfully");
                comboBox1.Text = "";
                comboBox2.Text = "";
                comboBox3.Text = "";
                comboBox4.Text = "";
                comboBox5.Text = "";
                comboBox6.Text = "";
                comboBox7.Text = "";
            }
            
        }
 how give if condition for this please help me


Answers (3)