Try enclosing your ID value in single quotes.
string myCommand = "SELECT * FROM Manager WHERE UserName='" + ID + "'";
Ezzaral
Posting Genius
15,986 posts since May 2007
Reputation Points: 3,250
Solved Threads: 847
I would highly recommend against building your queries dynamically like this. You should use parameterized SQL for security and performance reasons, please see:
http://www.daniweb.com/forums/thread176306.html
Here is sample code for your situation:
private void simpleButton1_Click(object sender, EventArgs e)
{
const string connStr = @"Data Source=apex2006sql;Initial Catalog=Leather;Integrated Security=True;";
const string query = "Select * From Invoice Where InvNumber = @InvNumber";
const int invNumber = 1100;
DataSet ds = new DataSet();
using (SqlConnection conn = new SqlConnection(connStr))
{
conn.Open();
using (SqlCommand cmd = new SqlCommand(query, conn))
{
cmd.Parameters.Add("@InvNumber", SqlDbType.Int).Value = invNumber;
using (SqlDataAdapter da = new SqlDataAdapter(cmd))
{
da.Fill(ds);
}
}
conn.Close();
}
}
sknake
Industrious Poster
4,954 posts since Feb 2009
Reputation Points: 1,764
Solved Threads: 735
CHECK THAT YOUR ID CONTAINS A VALUE OR NOT. I THINK YOUR ID DOES NOT CONTAIN VALUE... So THAT YOUR QUERY WILL BE LIKE WHERE ...= SO WHEN YOU EXECUTE THE QUERY GETS THIS ERROR.
This also gives another reason why parameterized queries should be used, because in the case of a blank ID it would run the query looking for null.
sknake
Industrious Poster
4,954 posts since Feb 2009
Reputation Points: 1,764
Solved Threads: 735