Click here to Skip to main content
15,886,519 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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
C#
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
Updated 9-Jan-13 21:06pm
v3
Comments
Joezer BH 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

Hi sreeCoderMan,

Please update your query line

C#
string sql;
sql = "SELECT UserName,Password from tblLogin where UserName= '" + txtU.Text + "', Password ='" + txtP.Text + "'";


with

C#
string sql;
sql = "SELECT UserName,Password from tblLogin where UserName= '" + txtU.Text + "' AND Password ='" + txtP.Text + "'";
 
Share this answer
 
v2
Comments
sreeCoderMan 10-Jan-13 3:13am    
thankyu its now working but if i keep a breakpoint in the button code its not breaking
Mohd. Mukhtar 10-Jan-13 3:16am    
For that you need to run your Visual Studio in Debug mode.
sreeCoderMan 10-Jan-13 3:19am    
<compilation debug="true">
sreeCoderMan 10-Jan-13 3:19am    
compilation debug="false"
VishalKadiwala 10-Jan-13 3:39am    
please set compilation debug="true"
You query should be like below

C#
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
 
Share this answer
 
hi,

the problem is on this line
C#
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..
SQL
select * from table_name where col_name=condition1 and col_name=condition2


but in your select query instead of and your using (,).
 
Share this answer
 
Comments
sreeCoderMan 10-Jan-13 4:11am    
thankyu buddy
Your query is wrong. Your query should be:
SQL
SELECT UserName,Password from tblLogin where UserName = 'userNamePassedFromCode' and Password = 'PasswordPassedFromCode'
 
Share this answer
 
Comments
sreeCoderMan 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)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900