anbu

anbu

  • NA
  • 3
  • 1.9k

C# and SQL question

Nov 12 2011 5:27 AM
Hello to everyone! I have one problem and don't know how to solve it so I need your help. I'm building a very simple application to insert text values into a database.

    private void button1_Click(object sender, EventArgs e)
        {
            SqlConnection conn = new SqlConnection(@"Data Source=BADRINATH-PC\SQLEXPRESS;Initial Catalog=Vremenik;Integrated Security=True;User Instance=False;");
            try
            {
                SqlCommand cmd = new SqlCommand("INSERT INTO dbo.profesori(Ime,Prezime,VrstaProvjere,DatumProvjere) VALUES ('" + textBox1.Text + "', '" + textBox2.Text + "','" + comboBox1.Text + "', '" + dateTimePicker1.Value.Date + "')", conn);
                conn.Open();
                cmd.ExecuteNonQuery();




                MessageBox.Show("Connection Succeful");
            }
            catch (SqlException ex)
            {
               
               MessageBox.Show("There is an Error" + ex);
            }
            finally
            {
                conn.Close();
                MessageBox.Show("Connection Closed");
            }
           
           
        }

 The problem is that I don't know how to check how many times is one value inserted into the specific column of the table? What to do for example if I don't want to have two same dates in my Date column? How can I solve this problem? 

Answers (2)