Skip to content

Getting error Incorrect syntax near '='

Marcu

Asked Sep 2, 2008, 9:13 AM EDT2 answers
Share
LinkedInX

I receive this error after the

 SQLDataReader reader  = command.ExecuteReader();

line during debugging. I have tried to figure out where this is at but have been unable to locate it. Can someone look at the end and determine where the error is. Here is my code:

 

PowerShell
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
namespace HSI
Code
{
public partial class login : System.Web.UI.Page
{
protected void Page_Load(object sender, System.EventArgs e)

{

 

 

}

 

private bool AuthenticateUser(string uname, string password, out int userID)

{

userID = -1;

bool bflag = false;

string queryString = "Server=hsisql;Database=hsi;Integrated Security=True";

string strSQL = "select * from icc_users where username ='" + uname + "' AND password ='" + password + "'";

 

 

 

 

 

 

 

 

using (SqlConnection connection = new SqlConnection(queryString))

{

SqlCommand command = new SqlCommand(queryString, connection);

connection.Open();

SqlDataReader reader = command.ExecuteReader();

{

// Call Read before accessing data.

if (reader.Read())

{

userID = System.Convert.ToInt32(reader[0]);bflag = true;
Code
}
// Call Close when done reading.
reader.Close();
}
return bflag;

}

}

protected void Login1_Authenticate1(object sender, AuthenticateEventArgs e)
C#
{
try
{
string uname = Login1.UserName.Trim(); //Get the username from the control
string password = Login1.Password.Trim(); //get the Password from the control
//changed
int userID;

bool flag = AuthenticateUser(uname, password, out userID);

if (flag == true)

{

e.Authenticated = true;

//Changed

HttpContext.Current.Session["userID"] = userID;Login1.DestinationPageUrl = "reports.aspx";

 

}

else

e.Authenticated = false;

}

catch (System.Exception)

{

e.Authenticated = false;

}

}

private bool AuthenticateUser(string uname, string password)

{

throw new System.Exception("The method or operation is not implemented.");
Code
}
}
}

2 Answers

Know the answer? Post it. Somebody with the same question will find it here.

  • Bechir Bejaoui
    +1
    OK, all you do is not appropriate because with this code any hacker could harm your application, the approriate way is to use a stored procedure and SQL parameters see the first part of my article of how to deal with this kind of issue click here
    +1
  • Bechir Bejaoui
    +1
    OK, all you do is not appropriate because with this code any hacker could harm your application, the approriate way is to use a stored procedure and SQL parameters see the first part of my article of how to deal with this kind of issue click here
    +1