elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.
 
Inicio Ayuda Buscar Ingresar Registrarse
28 Mayo 2012, 05:29  


Tema destacado: ¡Aprende hacking con práctica! - WarZone, el wargame de elhacker.net

+  Foro de elhacker.net
|-+  Programación
| |-+  Programación General
| | |-+  .NET (Moderador: [D4N93R])
| | | |-+  Visual~Sql===Logeo y llevar el valor de 1 variable a otro formulario
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: Visual~Sql===Logeo y llevar el valor de 1 variable a otro formulario  (Leído 603 veces)
_-Javier-_

Desconectado Desconectado

Mensajes: 17


凸 ◣_◢ ( Javier )◣_◢ 凸


Ver Perfil WWW
Visual~Sql===Logeo y llevar el valor de 1 variable a otro formulario
« en: 21 Enero 2011, 20:59 »

Bueno este es mi 4 post
aver si les interesa este ejercicio de logeo con conexión a sql
abrimos sql server 2008 y creamos una ew query y aplicamos el siguiente :


 
Código
go
use master
go
if (DB_ID('tienda')is not null)
drop database tienda
go
create database tienda
go
use tienda
go
sp_helpdb tienda
go
create table users
(dni char(8)primary key,
clave varchar(8)not null,
ape varchar(30)not null,
nom varchar(30)not null)
go
--------------------procedimiento loguear
create proc loguear(@dni char(8),@clave varchar(8),@datos varchar(62)output)
as begin
if(exists(select * from users where dni=@dni and clave=@clave ))
set @datos =(select ape +','+nom from users  where dni=@dni )
else
set @datos ='datos incorrectos'
end
go
insert users values('10203040','myPass','Rios flores','Jose'),
                    ('44556677','asd123','Paz gomes','Cinthia')
go
declare @datos varchar(62)
exec loguear '10203040','myPass',@datos output
select @datos
go
declare @datos varchar(62)
exec loguear '44556677','asd123',@datos output
select @datos
go
 
 

2_abrimos visual studio 2008 y creamos un new project(formulario windows)
2.1_ le agregamos un modulo con el siguiente:
  
Código
]
Imports System.Data
Imports System.Data.SqlClient
Module Module1
   Public Con As New SqlConnection("Data Source=.;DataBase=tienda;Integrated Security=true")
   Public Sub abrir()
       If Con.State = 0 Then Con.Open()
   End Sub
   Sub cerrar()
       If Con.State = 1 Then Con.Close()
 
   End Sub
   Public clave As String
End Module
 


3_ver interfaz del formulario


utilizaremos 2 botones y 2 textbox (txtdni-txtclave) y escribimos el siguiente
Código
]
Imports System.Data
Imports System.Data.SqlClient
Public Class acceso
   Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
       ingresar()
       txtdni.Text = ""
       txtclave.Text = ""
   End Sub
   Sub ingresar()
       Dim cmd As SqlCommand
       Dim msj As String
       Try
           Call abrir()
           cmd = New SqlCommand("loguear", Con)
           cmd.CommandType = CommandType.StoredProcedure
           With cmd.Parameters
               .AddWithValue("@dni", txtdni.Text)
               .AddWithValue("@clave", txtclave.Text)
               .Add("@datos", SqlDbType.VarChar, 62).Direction = 2
           End With
           cmd.ExecuteNonQuery()
           msj = cmd.Parameters("@datos").Value
           MessageBox.Show(msj)
           clave = cmd.Parameters("@datos").Value
           Me.Hide()
           My.Forms.accesoactivo.ShowDialog()
       Catch ex As Exception
           MessageBox.Show(ex.Message)
       End Try
       Call cerrar()
   End Sub
 
End Class
 

4_ahora agregamos un nuevo formulario llamado accesoactivo y aplicamos el siguiente.
 pero antes vemos la interfaz:(utilizando un toolstrip1 y le agregamos un toolstriptextbox1 llamado ttxtdatos(propiedad name))



Código
]
Imports System.Data
Imports System.Data.SqlClient
Public Class accesoactivo
   Private Sub accesoactivo_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
       ttxtdatos.Text = clave
   End Sub
End Class
 
-Listo . hemos terminado de hacer un logeo con BD .
_Despues de logearnos aparecera el nombre del dueño del dni en el ttxtdatos
_dni y pass estan en la BD (select * from users)
_bueno es todo ojala les sirva




« Última modificación: 29 Enero 2011, 17:20 por _-Javier-_ » En línea



Uploaded with ImageShack.us
Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

Powered by SMF 1.1.16 | SMF © 2006-2008, Simple Machines