Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sql search question

Status
Not open for further replies.

lordeos

IS-IT--Management
Aug 7, 2003
91
BE
I want to design a login screen in asp ... where the users with there passwords are entered in an sql database.

I have two textfields on the page . 1) username 2) password . How can i look up in the table if the username and the pasword excist and match ...???

What is the code i have to wrtite ??

Best regards ant thx in dadvance
Mike


 
Just do a simple query to see if any records exist for the username and password - faq855-5662


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
oke and after that ...

what is the code to check if the username and password is found ???

Ex

If "username and password is found then"
...... ????

thx
 
Just enter your code of what you want to do within the loop (either using the datareader or the datatable from that example) as if no match is found there will be no records returned and you wont enter into the loop.


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
hi,

Next problem / when i make a new "web application" in visual studio net and i put some textfield and buttons on it .. an i paste the code in the "on page load" section ... i change the database specifications to my database "its a database that is hosted elsewhere (could that be a problem???) ... it doesnt show anything ???
 
It will help it you show us your code and where you expect it should show data on the page...


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
hi

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim MyConnection As System.Data.SqlClient.SqlConnection
Dim MyDataAdapter As SqlClient.SqlDataAdapter
Dim MyDataTable As New DataTable()
Dim MyDataRow As DataRow
Dim strSQL As String = "SELECT FIELD1, FIELD2 FROM MYTABLE"

MyConnection = New System.Data.SqlClient.SqlConnection("server=sql13.hostbasket.com; initial catalog=mikeportaelsbe;uid=mikeportaelsbe;pwd=***")
MyConnection.Open()
MyDataAdapter = New SqlClient.SqlDataAdapter(strSQL, MyConnection)
MyDataAdapter.Fill(MyDataTable)
' Loop through DataTable
For Each MyDataRow In MyDataTable.Rows
'and then in need the code to check if the textfiels equals the characters in the database
'textbox1 (username) = .... (search for name)
'if the password entered is correct then a msbox ok

Next
 
For Each MyDataRow In MyDataTable.Rows
'and then in need the code to check if the textfiels equals the characters in the database
'textbox1 (username) = .... (search for name)
'if the password entered is correct then a msbox ok

Next
That code simpyl loops through each row but it doesn't attempt to write anything to the page. Have you placed any other code within that loop to write to the page?


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
I dont want to write tho the page ... iwant to extract the name and password i have entered in table1 ... and then check ik its the same .. then what the person entered in the textbox

Normally if enter a "msgbox ("ok") statement at the end it should give me two msgboxes because there are two rows, right ??????

thx for the help
 
Well i did enter a msgbox statement at the end ... but the page loads but doest do anything i even cant see the controls i added ... only when i change them to html controls i can see them ...

Thx for the help its the first time im trying to build a login page in this manner .
 
+ when i build it it creates a dll and not an html (what aim i doing wrong ??)
 
If you want to see what data is contained within a loop you could (while testing) use Response.Write to write the values out the the page so that you can see they are correct as you can't use msgbox as this is not a Windows Application.

As for the DLL, a dll is created to contain all your code behind pages and your aspx pages simply contain the HTML.

I suggest you read up on the basics of ASP.NET (try a site such as as you don't seem to have understood some of the fundamental principles of ASP.NET.



____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.
 
Hello,

I read the info about asp and i think i have some catching up to do :):)

This is what i learned :
<%@ Page Language="vb" AutoEventWireup="false" Codebehind="WebForm1.aspx.vb" Inherits="screenlogin.WebForm1"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<script language = vbscript runat=server>
Sub Button1_ServerClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.ServerClick
Dim MyConnection As System.Data.SqlClient.SqlConnection
Dim MyDataAdapter As SqlClient.SqlDataAdapter
Dim MyDataTable As New DataTable()
Dim MyDataRow As DataRow
Dim strSQL As String = "select* FROM tabel1"
Dim gebruiker As String
Dim invoer As String
Dim paswoord As Integer
Dim paswoord1 As Integer

MyConnection = New System.Data.SqlClient.SqlConnection("server=sql13.hostbasket.com; initial catalog=mikeportaelsbe;uid=mikeportaelsbe;pwd=tempus")
MyConnection.Open()
MyDataAdapter = New SqlClient.SqlDataAdapter(strSQL, MyConnection)
MyDataAdapter.Fill(MyDataTable)
message.text= "oke"
' Loop through DataTable

For Each MyDataRow In MyDataTable.Rows

'paswoord = CInt(MyDataRow.Item(2))
gebruiker = Trim(CStr(MyDataRow.Item(0)))
invoer = Trim(Me.Text1.Value)
If gebruiker = invoer Then
paswoord = Trim(CInt(MyDataRow.Item(1)))
paswoord1 = Trim(Me.Text2.Value)
If paswoord = paswoord1 Then
MsgBox("welcome" & gebruiker)
Else
MsgBox("Foute login")
End If
End If
'End If
'and then in need the code to check if the textfiels equals the characters in the database
'textbox1 (username) = .... (search for name)
'if the password entered is correct then a msbox ok
Next
End Sub
</script>

<title>WebForm1</title>
<meta name="GENERATOR" content="Microsoft Visual Studio.NET 7.0">
<meta name="CODE_LANGUAGE" content="Visual Basic 7.0">
<meta name="vs_defaultClientScript" content="vbscript">
<meta name="vs_targetSchema" content=" </HEAD>
<body MS_POSITIONING="GridLayout">
<form action ="Webform1.aspx" id="Form1" method="post" runat="server">
<INPUT id="Text1" style="Z-INDEX: 101; LEFT: 281px; POSITION: absolute; TOP: 38px" type="text" name="Text1" runat="server">
<INPUT id="Text2" style="Z-INDEX: 102; LEFT: 282px; POSITION: absolute; TOP: 116px" type="text" name="Text2" runat="server">
<INPUT id="Button1" style="Z-INDEX: 103; LEFT: 332px; POSITION: absolute; TOP: 202px" type="button" value="Button" name="Button1" runat="server">
<asp:Button OnClick = "Button1_Serverclick" </asp:Button>
</form>
</body>
</HTML>


But for some reason the button still doesnt react ,
Why??

Thx
 
The syntax is wrong and you'll need to make your control a server control by adding the RUNAT=SERVER:

<asp:Button OnClick = "Button1_Serverclick" RUNAT=SERVER></asp:Button>
 
since you're using VS.NET, consider using code-behind instead of the script thingie.
 
Hi this is the new version

<%@ Page Language="vb" AutoEventWireup="true" Codebehind="WebForm1.aspx.vb" Inherits="screenlogin.WebForm1"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>WebForm1</title>
<meta name="GENERATOR" content="Microsoft Visual Studio.NET 7.0">
<meta name="CODE_LANGUAGE" content="Visual Basic 7.0">
<meta name="vs_defaultClientScript" content="vbscript">
<meta name="vs_targetSchema" content=" </HEAD>
<body MS_POSITIONING="GridLayout">
<form action="Webform1.aspx" id="Form1" method="post" runat="server">
<INPUT id="Text1" style="Z-INDEX: 101; LEFT: 281px; POSITION: absolute; TOP: 38px" type="text" name="Text1" runat="server">
<INPUT id="Text2" style="Z-INDEX: 102; LEFT: 282px; POSITION: absolute; TOP: 116px" type="text" name="Text2" runat="server">
<asp:Button OnClick="Button1_ServerClick" Runat=server></asp:Button>
</form>
</body>
</HTML>

What is wrong about the code then??
 
But if i make it an asp button i dont see it anymore ????
 
This works -- I've checked it:

<%@ Page Language="vb" AutoEventWireup="false" Codebehind="WebForm1.aspx.vb" Inherits="screenlogin.WebForm1"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 TRANSITIONAL//EN">
<HTML>
<HEAD>
<TITLE>WebForm1</TITLE>
<META NAME="GENERATOR" CONTENT="Microsoft Visual Studio .NET 7.0">
<META NAME="CODE_LANGUAGE" CONTENT="Visual Basic .NET 7.0">
<META NAME=vs_defaultClientScript CONTENT="JavaScript">
<META NAME=vs_targetSchema CONTENT=" </HEAD>
<BODY MS_POSITIONING="GridLayout">

<FORM ID="Form1" METHOD="post" RUNAT="server">
<INPUT ID="Text1" STYLE="Z-INDEX: 101; LEFT: 281px; POSITION: absolute; TOP: 38px" TYPE="text" NAME="Text1" RUNAT="server">
<INPUT ID="Text2" STYLE="Z-INDEX: 102; LEFT: 282px; POSITION: absolute; TOP: 116px" TYPE="text" NAME="Text2" RUNAT="server">
<ASP:BUTTON ID="BtnSub" RUNAT=server TEXT="Submit" ></ASP:BUTTON>

</FORM>

</BODY>
</HTML>
 
[*cough*] basic [*cough*] training [*cough*]

"...we both know I'm training to become a cagefighter...see what happens if you try 'n hit me..."
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top