hola! quisiera pedir su ayuda tengo el suiguiente codigo, con el cual pido nombre y contraseña lo cual consulto en una base de datos sql server 2005 y si esta el usuario lo dirige al index.aspx si no esta, marca error, entonces es lo que no me sale, como saber si la consulta fue exitosa o no y como seria el log out,
AYUDA PARA ENTRAR Y SALIR DEL SISTEMA
CODIGO:
<%@ Page language="C#" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<script runat="server">
void Alta(Object sender, EventArgs args){
SqlConnection conexion = new SqlConnection("server=(local);database=d…
String sentencia="select * from dbo.usuario where usuario = @usuario AND password = @password";
SqlCommand comando=new SqlCommand (sentencia,conexion);
int resultado;
try{
conexion.Open();
comando.Parameters.Add(new SqlParameter("@usuario",SqlDbType.NVarCh… 10));
comando.Parameters["@usuario"].Value = usuario.Text;
comando.Parameters.Add(new SqlParameter("@password",SqlDbType.NVarC… 20));
comando.Parameters["@password"].Value = password.Text;
resultado=comando.ExecuteNonQuery();
if (resultado == 1)
Response.Redirect("/data/priv/index2.asp…
Response.Write("Se iniciado " + resultado + " sesion " + " <a href=MostEmp.aspx>Ver Usuarios</a>");
Response.Write("<br><br>");
conexion.Close();
}
catch(SqlException e){
Response.Write("se ha producido una excepción: "+e);
}
}
</script>
<html>
<head><title>Inisiar Sesion</title></head>
<body>
<div id="cabecera">
<img src="img/data.jpg">
</div>
<br>
<h1><center> Iniciar Sesion </center></h1>
<form runat="server" id="formulario">
<asp:Label Runat="server" ID="TextoUsuario" text="usuario"/>
<asp:TextBox Runat="server" ID="usuario"/><br/>
<asp:Label Runat="server" ID="Textpassword" text="password"/>
<asp:TextBox Runat="server" ID="password"/><br/>
<br/>
<asp:Button OnClick="Alta" Runat="server" ID="boton" Text="Entrar"/>
</form>
</body>
</html>
AYUDA PARA ENTRAR Y SALIR DEL SISTEMA
CODIGO:
<%@ Page language="C#" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<script runat="server">
void Alta(Object sender, EventArgs args){
SqlConnection conexion = new SqlConnection("server=(local);database=d…
String sentencia="select * from dbo.usuario where usuario = @usuario AND password = @password";
SqlCommand comando=new SqlCommand (sentencia,conexion);
int resultado;
try{
conexion.Open();
comando.Parameters.Add(new SqlParameter("@usuario",SqlDbType.NVarCh… 10));
comando.Parameters["@usuario"].Value = usuario.Text;
comando.Parameters.Add(new SqlParameter("@password",SqlDbType.NVarC… 20));
comando.Parameters["@password"].Value = password.Text;
resultado=comando.ExecuteNonQuery();
if (resultado == 1)
Response.Redirect("/data/priv/index2.asp…
Response.Write("Se iniciado " + resultado + " sesion " + " <a href=MostEmp.aspx>Ver Usuarios</a>");
Response.Write("<br><br>");
conexion.Close();
}
catch(SqlException e){
Response.Write("se ha producido una excepción: "+e);
}
}
</script>
<html>
<head><title>Inisiar Sesion</title></head>
<body>
<div id="cabecera">
<img src="img/data.jpg">
</div>
<br>
<h1><center> Iniciar Sesion </center></h1>
<form runat="server" id="formulario">
<asp:Label Runat="server" ID="TextoUsuario" text="usuario"/>
<asp:TextBox Runat="server" ID="usuario"/><br/>
<asp:Label Runat="server" ID="Textpassword" text="password"/>
<asp:TextBox Runat="server" ID="password"/><br/>
<br/>
<asp:Button OnClick="Alta" Runat="server" ID="boton" Text="Entrar"/>
</form>
</body>
</html>