Hi, i met this error in asp.net. I was trying to make a login page, which enable user choose admin or user in radiobuttonlist. If admin login, he will go to admin page. It will check the admin name and password which is built in database.I use the same method for user. User already sign up, his name and password already put inside database. User login will go to user page. But when i want to check whether user name and password in database, i get syntax error.

Here is the code for button click login.
Protected Sub loginButton_Click(sender As Object, e As EventArgs) Handles loginButton.Click Dim na As String Dim pa As String Dim dv As DataView Dim rs As Integer na = username.Text pa = password.Text If RadioButtonList1.SelectedValue = "Administrator" Then SqlDataSource1.SelectCommand = "select * from admin where name = '" & na & "' and password = '" & pa & "'" dv = CType(SqlDataSource1.Select(DataSourceSelectArguments.Empty), DataView) If dv.Count = 1 Then Response.Redirect("HomeAdmin.aspx") Else Label8.Text = "Invalid admin name or password, Please key in again !" End If Else SqlDataSource2.SelectCommand = "select * from user where name = '" & na & "' and password = '" & pa & "'" dv = CType(SqlDataSource2.Select(DataSourceSelectArguments.Empty), DataView) If dv.Count = 1 Then Response.Redirect("HomeUser.aspx") Else Label8.Text = "Invalid user name or password, Please key in again !" End If End IfI have no problem when i login with admin, but got error when login with user. Thanks for Help!
-
Can you specify the exact error?Sankar– Sankar2015-11-22 04:20:43 +00:00Commented Nov 22, 2015 at 4:20
-
I can choose radiobutton between user and admin. But i cannot get the userdata from the database to login into the page.However, i can get the admin data from database and login in with admin. I use the same coding concept with admin to apply on user. I duno what is the error means for me.kenreal– kenreal2015-11-22 04:25:01 +00:00Commented Nov 22, 2015 at 4:25
-
You need to provide more detail regarding the error. Code you posted has no issues. Check the SqlDataSource2 connection string may be that is causing the issue.user1331032– user13310322015-11-22 04:44:41 +00:00Commented Nov 22, 2015 at 4:44
-
the sqldatasource2 is connect to user table. user table consist of three data which are name,email,password.That is for storing user name,email and password in database. And my select statement is select * from user. However, user just have to enter name and password to login.kenreal– kenreal2015-11-22 04:50:20 +00:00Commented Nov 22, 2015 at 4:50
-
I also try select name and password from user. But the error still come out. I have no idea on this. Changing select statement in the connection string.kenreal– kenreal2015-11-22 04:51:45 +00:00Commented Nov 22, 2015 at 4:51
Add a comment
|
2 Answers
why do you use two sqldatasources? you need just one. Use one sqldatasource.
1 Comment
kenreal
one sqldatasources for user, one sqldatasources for admin. If choose admin, go inside admin sqldatasources. There are 2 table, so i use two sqldatasources..If use one sqldatasources, can i select useror admin?
