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?
Loading
nishant ranjanPosted Nov 12, 2011, 5:37 AM
if u dont want that same date should be entered in any other row.
so first select the date and match that date with textbox.text where date is entered. if it doesnot match then execute insert command or else display duplicate value
anbuPosted Nov 16, 2011, 12:04 PM