I have created a login form in asp.net web page.Just like that I have created a table named login which has 2 fields as username & password in SQL Server 2000. I have to check whether the data(username & password) entered in the front end is available(exist s) in the back end (SQL Server 2000) or not.
To check whether the data exists in the back end or not
Collapse
X
-
if the user enter
username in Textbox1
password in Textbox2
use this query
DavidsonCode:dim rd as new sqldatareader dim cmd as new sqlcommand("select count(*) from login where username=' " & textbox1.text & " ' and password=' " & textbox2.text & " ' ",cn) rd=cmd.executereader() if rd(0)=0 then Response.write("Invalid User") exit sub else Response.write("Valid User") end if
10 march 2008 -
this is like assignment.
u have to following steps on login button click event
1) Declare connection and command object
Dim oSqlcon as SqlConection
Dim oSqlcmd as SqlCommand
2) Open connection
oSqlCon = New SqlConnection(c onnection string)
oSqlCon.Open()
3) create command object
oSqlCmd = new SqlCommand()
4) assing query and execute query
oSqlCmd.connect ion = oSqlcon
oSqlCmd.command Text = "select userid from userTable where loginname=' "& Trim( txtloginname.te xt ) &" ' and password= ' ''& Trim(txtPwd.tex t) &" ' "
Dim cnt as Int32
cnt = oSqlCmd.execute scalar()
if cnt <=0 then
Response.write( "Un-authorise user")
else
Response.write( "Authorise user")
end ifComment
Comment