[RESOLVED] [2.0] this is a really simple question
And I should know it but I don't...
What is the simplest way to check for the existence of a value in a database. Like I wanna know if studyIdNumber FF12033 already has been inserted. I have like 14 lines of code to do it. There has to be a better way.
Thanks
Re: [2.0] this is a really simple question
c# Code:
//your SqlConnection here, name it conn
//SqlCommand
Sqlcommand cmd = new SqlCommand();
cmd.CommandText = "Select Count(studyIdNumber) from table_name WHERE studyIdNumber='FF12033'";
cmd.Connection = conn;
conn.Open();
int num_of_instance = cmd.ExecuteScalar();
conn.Close();
if (num_of_instance == 1)
{
//Item already inserted
}
else
{
//Insert new Item
}
Hope it helps!!
Re: [2.0] this is a really simple question
Wowser... As soon as you posted that I realized I had done that before. what can I say? It is the day after the fourth.
Thanks!