Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
hi friends
 
i have a adminlogin page inside a admin folder not in root directory
 
in adminlogin.aspx page there is login form ( NOT LOGIN TOOLBOX) there a button called Signin if i click the signin button am getting a error:
 
ERROR : Incorrect Syntax near','.
 
the even is not firing in button
pleas help me
should i need two webconfig file inside admin folder?
 

my login Button Code
thin LoginButton is in admin folder not in root directory the page is login.aspx
protected void btnLog_Click(object sender, EventArgs e)
    {
        String constr = ConfigurationManager.ConnectionStrings["MyProject"].ConnectionString;
        SqlConnection con = new SqlConnection(constr);
        con.Open();
 
        string sql;
        sql = "SELECT UserName,Password from tblLogin where UserName= '" + txtU.Text + "', Password ='" + txtP.Text + "'";
        SqlCommand cmd = new SqlCommand(sql,con);
        
        cmd.Parameters.AddWithValue("@UserName", txtU.Text);
        cmd.Parameters.AddWithValue("@Password", txtP.Text);
 
        SqlDataAdapter da = new SqlDataAdapter(cmd);
 
        DataTable dt = new DataTable();
        //Session.Timeout = 60;
        da.Fill(dt);
 
        if (dt.Rows.Count > 0)
        {
            Response.Redirect("~/admin/MainPage.aspx");
        }
        else
        {
            Response.Write("Login failed");
        }
      
 
    }
Posted 9-Jan-13 21:53pm
Edited 9-Jan-13 22:06pm
v3
Comments
Edo Tzumer at 10-Jan-13 2:57am
   
Hello sreeCodeMan, Show some more details, if you want us to pick up the problem.
Some some code of the aspx page and details of the error if you can gather them.
 
Cheers,
Edo
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Hi sreeCoderMan,
 
Please update your query line
 
string sql;
sql = "SELECT UserName,Password from tblLogin where UserName= '" + txtU.Text + "', Password ='" + txtP.Text + "'";
 
with
 
string sql;
sql = "SELECT UserName,Password from tblLogin where UserName= '" + txtU.Text + "' AND Password ='" + txtP.Text + "'";
  Permalink  
v2
Comments
sreeCoderMan at 10-Jan-13 3:13am
   
thankyu its now working but if i keep a breakpoint in the button code its not breaking
Mohd. Mukhtar at 10-Jan-13 3:16am
   
For that you need to run your Visual Studio in Debug mode.
sreeCoderMan at 10-Jan-13 3:19am
   
sreeCoderMan at 10-Jan-13 3:19am
   
compilation debug="false"
VishalClarion at 10-Jan-13 3:39am
   
please set compilation debug="true"
sreeCoderMan at 10-Jan-13 3:41am
   
still not working
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

You query should be like below
 
sql = "SELECT UserName,Password from tblLogin where UserName= @UserName and Password =@Password";
SqlCommand cmd = new SqlCommand(sql,con);
        
        cmd.Parameters.AddWithValue("@UserName", txtU.Text.Trim());
        cmd.Parameters.AddWithValue("@Password", txtP.Text.Trim());
 
 
 
Thanks
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

hi,
 
the problem is on this line
 sql = "SELECT UserName,Password from tblLogin where UserName= '" + txtU.Text + "', Password ='" + txtP.Text + "'";
 
your callling select statement that is not correct format.
 
the select query is like this..
 select * from table_name where col_name=condition1 and col_name=condition2
 
but in your select query instead of and your using (,).
  Permalink  
Comments
sreeCoderMan at 10-Jan-13 4:11am
   
thankyu buddy
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Your query is wrong. Your query should be:
SELECT UserName,Password from tblLogin where UserName = 'userNamePassedFromCode' and Password = 'PasswordPassedFromCode'
  Permalink  
Comments
sreeCoderMan at 10-Jan-13 3:14am
   
you are correct

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



Advertise | Privacy | Mobile
Web03 | 2.8.1411022.1 | Last Updated 10 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100