I am trying to check if there is a row present in a SQL Server table or not.
If the row exists (on a particular TicketID
), it should show a messagebox that you can't continue further as there is already an entry in database. But if there isn't, it should insert some records (on that particular TicketID
).
I tried try and catch but wasn't able to do it :
Here is the code of query: (hardcoded ticketID
for example)
bool no;
try
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ST"].ConnectionString.ToString());
con.Open();
cmd.CommandText = "SELECT EngineerVisited from tblTicketTechnical where TicketID=1";
cmd.Connection = con;
rdr = cmd.ExecuteReader();
while (rdr.Read())
{
bool = rdr.GetBoolean(0);
}
con.Close();
}
catch
{
MessageBox.Show("Cannot continue");
}
I would really appreciate if someone could suggest a function that will return true if row is found and return false, if it isn't.
You can use HasRows property of SQLDataReader
.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments