I have a table named tbDepartment
(id, title, abbreviation) and a GridView
containing two columns Title and Abbreviation
I need to know if the Title inserted by the user in the gridView is equal to the one in the table tbDepartment
. If true I want to get the id, otherwise I need to create new user.
What I wrote is not entering the if statement. Can someone tell me how to correct it?
string sql2 = "Insert into tbDepartment ([Title], [Abbreviation]) values (@Desc, @DepCode)";
string sqlDep = "Select [ID] from tbDepartment where Title = '" + gridView3.GetRowCellValue(i, gridView3.Columns[DepCode]).ToString() +"'" ;
SqlCommand cmdDep = new SqlCommand(sql2, connection);
if (sqlDep == 0)
{
cmdDep.Parameters.Add("@Desc", SqlDbType.VarChar,50);
cmdDep.Parameters.Add("@DepCode", SqlDbType.VarChar, 50);
cmdDep.Parameters["@Desc"].Value = Convert.ToString(gridView3.GetRowCellValue(i, gridView3.Columns[DepDesc]));
cmdDep.Parameters["@DepCode"].Value = Convert.ToString(gridView3.GetRowCellValue(i, gridView3.Columns[DepCode]));
}