Jump to content
Whiteangel

Login - Utilizadores

Recommended Posts

Whiteangel

Boas pessoal,

Estou a fazer um login, e nesse login só já me falta verificar se o nome do utilizador (user name), ja existe na base de dados, eu sei que tem de ser através de uma consulta --> "Select * From Login " & "Where Nome= '" & nome & "'"

Mas não sei como faça no meu codigo, deixo aqui o meu codigo a ver se alguém de pode dar umas dicas :)

If TxtPassword.Text = TxtConfPassword.Text Then

		If TxtNome.Text = "" And TxtPassword.Text = "" And TxtConfPassword.Text = "" And TxtNomeComp.Text = "" And TxtMorada.Text = "" And MTBTelemovel.Text = "" And ComboSexo.Text = "" And ComboEstado.Text = "" And TxtEmail.Text = "" And TxtCodigo.Text = "" And MTBData.Text = "" And TxtLocalidade.Text = "" Then

			LbNome.ForeColor = Color.Red
			Lbpassword.ForeColor = Color.Red
			LbConfpassword.ForeColor = Color.Red
			LbNomeComp.ForeColor = Color.Red
			Lbmorada.ForeColor = Color.Red
			Lbtelemovel.ForeColor = Color.Red
			Lbestado.ForeColor = Color.Red
			Lbsexo.ForeColor = Color.Red
			Lbemail.ForeColor = Color.Red
			Lbcodigo.ForeColor = Color.Red
			Lbdata.ForeColor = Color.Red
			LbLocalidade.ForeColor = Color.Red
			LbCampos.Visible = True

		ElseIf TxtNome.Text = "" Then
			LbCampos.Visible = True
		ElseIf TxtPassword.Text = "" Then
			LbCampos.Visible = True
		ElseIf TxtConfPassword.Text = "" Then
			LbCampos.Visible = True
		ElseIf TxtNomeComp.Text = "" Then
			LbCampos.Visible = True
		ElseIf TxtMorada.Text = "" Then
			LbCampos.Visible = True
		ElseIf MTBTelemovel.Text = "" Then
			LbCampos.Visible = True
		ElseIf ComboSexo.Text = "" Then
			LbCampos.Visible = True
		ElseIf ComboEstado.Text = "" Then
			LbCampos.Visible = True
		ElseIf TxtEmail.Text = "" Then
			LbCampos.Visible = True
		ElseIf TxtCodigo.Text = "" Then
			LbCampos.Visible = True
		ElseIf MTBData.Text = "" Then
			LbCampos.Visible = True
		ElseIf TxtLocalidade.Text = "" Then
			LbLocalidade.Visible = True

		Else
			Dim myConnectionString As String = _
			"Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\Acer\Documents\Visual Studio 2010\Projects\PAP\BaseDados\SS.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True"

			Dim Sql As String = "INSERT INTO Login (Nome, Password, NomeCompleto, Morada, sexo, EstadoCivil, Telemovel, Email, DataNascimento, CodigoPostal, Localidade ) VALUES( @Nome, @Password, @NomeCompleto, @Morada, @sexo, @EstadoCivil, @Telemovel, @Email, @DataNascimento, @CodigoPostal, @Localidade)"

			Dim connection As New SqlConnection(myConnectionString)

			connection.Open()

			Try


				Dim command As New SqlCommand(Sql, connection)
				command.Parameters.Add(New SqlParameter("@Nome", TxtNome.Text))
				command.Parameters.Add(New SqlParameter("@password", TxtPassword.Text))
				command.Parameters.Add(New SqlParameter("@NomeCompleto", TxtNomeComp.Text))
				command.Parameters.Add(New SqlParameter("@Morada", TxtMorada.Text))
				command.Parameters.Add(New SqlParameter("@Sexo", ComboSexo.Text))
				command.Parameters.Add(New SqlParameter("@EstadoCivil", ComboEstado.Text))
				command.Parameters.Add(New SqlParameter("@Telemovel", MTBTelemovel.Text))
				command.Parameters.Add(New SqlParameter("@Email", TxtEmail.Text))
				command.Parameters.Add(New SqlParameter("@CodigoPostal", TxtCodigo.Text))
				command.Parameters.Add(New SqlParameter("@DataNascimento", MTBData.Text))
				command.Parameters.Add(New SqlParameter("@Localidade", TxtLocalidade.Text))

				command.ExecuteNonQuery()
				command.Dispose()


			Catch ex As Exception

			Finally
				connection = Nothing

			End Try

			MsgBox("Registo Efectuado com sucesso", MsgBoxStyle.Information, "Mensagem de Confirmação")
			Login.Show()
			Me.Hide()
		End If

	Else
		MsgBox("Password incorrecta", MsgBoxStyle.Critical, "Mensagem de Erro")
		TxtPassword.ResetText()
		TxtConfPassword.ResetText()
	End If

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.