Hello i have the following cs code
SqlConnection con = new SqlConnection();
SqlCommand com = new SqlCommand();
String comando = "";
con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["INBIOTECAConnectionString"].ToString());
SqlDataReader leer = null;
String diaUltimo = "";
String fecha = DateTime.Now.ToString("dd/MM/yyyy");
try
{
con.Open();
comando = " SELECT TOP 1 hora FROM SI_RegEntrada WHERE nombre = '" + name + "' and dia = '"+fecha+"' ORDER BY id DESC;";
com = new SqlCommand(comando, con);
leer = com.ExecuteReader();
while (leer.Read())
{
diaUltimo = leer[0].ToString();
}
if (diaUltimo.Equals(""))
{
return false;
}
else
{
return true;
}
}
catch (Exception ex)
{
return true;
}
finally
{
con.Close();
con.Dispose();
com.Dispose();
com = null;
con = null;
}
It's supposed to be pretty simple, it's gonna check if there's an entry on the SI_RegEntrada table today (fecha) from any user (name).
SELECT TOP 1 hora FROM SI_RegEntrada WHERE nombre = '" + name + "' and dia = '"+fecha+"' ORDER BY id DESC;
ok, so far so good, i proceed to read the results on the var diaUltimo.
On my local server, if there are no results (meaning that today, that user, hasn't interact with the system), diaUltimo will get the value of
diaUltimo = ""
so I check for that in the if/else condition a return true or false. In the live server, it always falls on the catch clause, and return always true.
I was thinking that, maybe diaUltimo will get some kind of null value, or some sql error.
I cannot debug or interact with the live server.