The error I am receiving is “Incorrect syntax near ‘user'” – however, I cannot see anything wrong with my code – does anyone have any ideas?
protected void Page_Load(object sender, EventArgs e)
{
string db = "";
db = ConfigurationManager.ConnectionStrings["myConnection"].ConnectionString;
SqlConnection con = new SqlConnection(db);
con.Open();
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "SELECT * FROM user";
cmd.Connection = con;
SqlDataReader dr;
dr = cmd.ExecuteReader();
while (dr.Read())
{
Response.Write(dr[0].ToString());
Response.Write(dr[1].ToString());
Response.Write(dr[2].ToString());
Response.Write(dr[3].ToString());
}
con.Close();
}
Try this
useris a keyword/reserved word. I guess that’s the problem. I always end up usingUSERSinstead ofuser. Try as much as possible to avoid using reserved words as column names, table names, etc. Use them whenever you can’t avoid it