Tema: Sql con if
Ver Mensaje Individual
  #5 (permalink)  
Antiguo 26/05/2005, 09:23
Avatar de Nombela
Nombela
 
Fecha de Ingreso: abril-2005
Mensajes: 611
Antigüedad: 19 años, 10 meses
Puntos: 1
Gracias

Hablaba de administrador en base de datos pero al final tuve que cambiar mi sql xq me hacia que no pudiera borrar ningun administrador y solo queria que fuera cuando era el ultimo.

Al final lo resolvi asi:

myConnection = new SqlConnection (connectionString);
string ultimoCmd = "SELECT COUNT(*) AS total FROM Usuarios INNER JOIN Clientes ON Usuarios.UsIdCli = Clientes.UsIdCli GROUP BY Usuarios.UsIdPer, Clientes.UsIdCli "+
"HAVING (Usuarios.UsIdPer = 7) AND (Clientes.UsIdCli = "+Request.QueryString["id"]+")";
myCommand = new SqlCommand(ultimoCmd,myConnection);
myCommand.Connection.Open();
total = ((int)myCommand.ExecuteScalar());
myCommand.Connection.Close();
if (total==1)
{
mensage.Text = "ERROR: No se puede borrar el registro por ser el ultimo usuario administrador";
mensage.Style["color"] = "red";
}
else
{
string deleteCmd = "DELETE FROM Usuarios WHERE (UsId = @UsId)";
.....