login code - Visual Basic 6.0

  • (3 Pages)
  • +
  • 1
  • 2
  • 3

33 Replies - 54832 Views - Last Post: 24 August 2010 - 08:10 AM Rate Topic: -----

#16 antukin_cs  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 23
  • Joined: 06-October 07

Re: login code - Visual Basic 6.0

Posted 12 October 2007 - 07:29 AM

il try man...if an error occurs il post it...thanks!
Was This Post Helpful? 0
  • +
  • -

#17 antukin_cs  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 23
  • Joined: 06-October 07

Re: login code - Visual Basic 6.0

Posted 12 October 2007 - 07:43 AM

hey Louisda16th! your code works! thanks a lot man! although u broke the rules in this site man u still rock! nywei i really need to study SQL.... thanks again!
Was This Post Helpful? 0
  • +
  • -

#18 Louisda16th  Icon User is offline

  • dream.in.assembly.code
  • member icon

Reputation: 15
  • View blog
  • Posts: 1,967
  • Joined: 03-August 06

Re: login code - Visual Basic 6.0

Posted 12 October 2007 - 07:54 AM

Nah! I don't think I broke any rules. I don't think teaching someone new is breaking the rules :) (I hope it isn't). Give me a minute. I'm trying to figure out how to use find() as well. I never used it so I don't quite remember how to get it to work. Give me some time. :)
Was This Post Helpful? 0
  • +
  • -

#19 Louisda16th  Icon User is offline

  • dream.in.assembly.code
  • member icon

Reputation: 15
  • View blog
  • Posts: 1,967
  • Joined: 03-August 06

Re: login code - Visual Basic 6.0

Posted 12 October 2007 - 08:09 AM

Alright. Here's how Find works. Firstly, your recordsource must be set to 2-adCommandTable and your table name to whatever name you are using.
For find to work, you'll have to bind a control to your ADODC. So create a textbox and bind it. Now the following code should work easily. Im surely you'll be able to understand what's happening :).
  Adodc1.Recordset.Find "UserName ='" + txtUserName.Text + "'", 0, adSearchForward, adBookmarkFirst
	

	If (Adodc1.Recordset.EOF = False) Then
		If (txtPassword.Text = Adodc1.Recordset.Fields("Password")) Then
			MsgBox ("Login Successful")
		Else
			MsgBox ("Login Failure. Incorrect Password")
		End If
	Else
		MsgBox ("Login Failure. Username does not exist.")
	End If


Don't ask me why you need to bind a control. I don't know.
Was This Post Helpful? 0
  • +
  • -

#20 antukin_cs  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 23
  • Joined: 06-October 07

Re: login code - Visual Basic 6.0

Posted 12 October 2007 - 08:44 PM

is this code an SQL already??? i cant use SQL bcoz our instructor hasnt taught us that yet....
Was This Post Helpful? 0
  • +
  • -

#21 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1619
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: login code - Visual Basic 6.0

Posted 12 October 2007 - 08:49 PM

View Postantukin_cs, on 12 Oct, 2007 - 08:44 PM, said:

is this code an SQL already??? i cant use SQL bcoz our instructor hasnt taught us that yet....


The language that interacts with SQL is the same language that interacts with Access, Transact-SQL is simply the programming language that interacts with those 2 database types.

The database code you are viewing from Louisda16th is Transact-SQL, you can take that query and run it in either Microsoft SQL Server or Microsoft Access.
Was This Post Helpful? 0
  • +
  • -

#22 antukin_cs  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 23
  • Joined: 06-October 07

Re: login code - Visual Basic 6.0

Posted 12 October 2007 - 08:56 PM

hey Louisda16th, heres the code that my instructor gave us...can u fix it?? its not workin....


Private Sub cmdOK_Click()
static y as integer
adodc1.refresh
with adodc1.recordset

if .recordset > 0 then
.movefirst
.find "Username'="&txtUsername&"'"
.find "Password='"&txtPassword&"'"
if .EOF=false then
if !Username=txtUsername and !Password=txtPassword then
unload me
msgbox"Access granted!"
end if
end sub




anybody please help me!

View PostPsychoCoder, on 12 Oct, 2007 - 08:49 PM, said:

View Postantukin_cs, on 12 Oct, 2007 - 08:44 PM, said:

is this code an SQL already??? i cant use SQL bcoz our instructor hasnt taught us that yet....


The language that interacts with SQL is the same language that interacts with Access, Transact-SQL is simply the programming language that interacts with those 2 database types.

The database code you are viewing from Louisda16th is Transact-SQL, you can take that query and run it in either Microsoft SQL Server or Microsoft Access.



well i cant use that code.. i posted the code our instructor gave us..maybe you can fix it... :D

This post has been edited by antukin_cs: 12 October 2007 - 08:54 PM

Was This Post Helpful? 0
  • +
  • -

#23 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1619
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: login code - Visual Basic 6.0

Posted 12 October 2007 - 09:20 PM

Well if its not working, you need to explain what its doing, any errors you're receiving and things like that please :)
Was This Post Helpful? 0
  • +
  • -

#24 antukin_cs  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 23
  • Joined: 06-October 07

Re: login code - Visual Basic 6.0

Posted 12 October 2007 - 09:31 PM

.find "Username'="&txtUsername&"'"
.find "Password='"&txtPassword&"'"

these codes were highlighted after typing them....
Was This Post Helpful? 0
  • +
  • -

#25 Louisda16th  Icon User is offline

  • dream.in.assembly.code
  • member icon

Reputation: 15
  • View blog
  • Posts: 1,967
  • Joined: 03-August 06

Re: login code - Visual Basic 6.0

Posted 13 October 2007 - 12:08 AM

Did you bind a control to your ADODC. The code your instructor gave you is similar to the code I gave (see the second snippet). I mentioned that you have to create a separate control which is bound to your ADODC. Also in design mode, set recordsource to cmdTable and Table Name to the name of the table you are using.

And DONOT direct your posts towards a particular member. You'll get lesser replies. There are people here a billion times better than me in VB.
Was This Post Helpful? 0
  • +
  • -

#26 russell214  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 31
  • Joined: 22-February 06

Re: login code - Visual Basic 6.0

Posted 13 October 2007 - 08:17 PM

antukin_cs

Bro, change the code

.find "Username'="&txtUsername&"'"
.find "Password='"&txtPassword&"'"

with this one

.find "Username = '" & trim(txtUsername) &"'"
.find "Password = '" & trim(txtPassword) &"'"


Note: I add trim to remove the trailing space/s.

Hope this help.

Project ba bro?
Was This Post Helpful? 0
  • +
  • -

#27 antukin_cs  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 23
  • Joined: 06-October 07

Re: login code - Visual Basic 6.0

Posted 14 October 2007 - 10:26 PM

View Postrussell214, on 13 Oct, 2007 - 08:17 PM, said:

antukin_cs

Bro, change the code

.find "Username'="&txtUsername&"'"
.find "Password='"&txtPassword&"'"

with this one

.find "Username = '" & trim(txtUsername) &"'"
.find "Password = '" & trim(txtPassword) &"'"


Note: I add trim to remove the trailing space/s.

Hope this help.

Project ba bro?


yeah, enrollment system... where wud i replace these code?? to d original dat i gave out??
Was This Post Helpful? 0
  • +
  • -

#28 russell214  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 31
  • Joined: 22-February 06

Re: login code - Visual Basic 6.0

Posted 14 October 2007 - 10:56 PM

View Postantukin_cs, on 14 Oct, 2007 - 10:26 PM, said:

View Postrussell214, on 13 Oct, 2007 - 08:17 PM, said:

antukin_cs

Bro, change the code

.find "Username'="&txtUsername&"'"
.find "Password='"&txtPassword&"'"

with this one

.find "Username = '" & trim(txtUsername) &"'"
.find "Password = '" & trim(txtPassword) &"'"


Note: I add trim to remove the trailing space/s.

Hope this help.

Project ba bro?


yeah, enrollment system... where wud i replace these code?? to d original dat i gave out??


Here is yout original code

Private Sub cmdOK_Click()
static y as integer
adodc1.refresh
with adodc1.recordset

if .recordset > 0 then
.movefirst
.find "Username'="&txtUsername&"'" ' this is the error replace with ***
.find "Password='"&txtPassword&"'" '
if .EOF=false then
if !Username=txtUsername and !Password=txtPassword then
unload me
msgbox"Access granted!"
end if
end sub

----

***

.find "Username = '" & trim(txtUsername) &"'"
.find "Password = '" & trim(txtPassword) &"'"
Was This Post Helpful? 0
  • +
  • -

#29 Louisda16th  Icon User is offline

  • dream.in.assembly.code
  • member icon

Reputation: 15
  • View blog
  • Posts: 1,967
  • Joined: 03-August 06

Re: login code - Visual Basic 6.0

Posted 14 October 2007 - 11:02 PM

The move first isnt quite necessary. Look at this:
Adodc1.Recordset.Find "UserName ='" + txtUserName.Text + "'", 0, adSearchForward, adBookmarkFirst



The last argument, adBookMarkFirst takes care of it. See Post #19 again. I haven't used SQL at all. I think it should serve your purpose. Just remember to create an extra textbox/label and bind it to your ADO data control.
Hope this helps :).
Was This Post Helpful? 0
  • +
  • -

#30 Louisda16th  Icon User is offline

  • dream.in.assembly.code
  • member icon

Reputation: 15
  • View blog
  • Posts: 1,967
  • Joined: 03-August 06

Re: login code - Visual Basic 6.0

Posted 14 October 2007 - 11:09 PM

Quote

.find "Username = '" & trim(txtUsername) &"'"
.find "Password = '" & trim(txtPassword) &"'"

A small problem with this. Your code will first check for a record with the username matching. Next it will check for a record with the password matching. You won't quite achieve anything with this. Let me explain. Suppose you have a table like this:
UserName		  PassWord
Scott					  tiger
Andrew				 cheetah
Peter					 lion



Suppose you enter Andrew for username and tiger for password, at the end of the two find statements, you'll end up at record 1. Now that's not the record Andrew was looking at. It'll return an incorrect username instead of password. I hope Im making sense :).

Hope this helps :).

This post has been edited by Louisda16th: 14 October 2007 - 11:11 PM

Was This Post Helpful? 0
  • +
  • -

  • (3 Pages)
  • +
  • 1
  • 2
  • 3