I'm developing a code for a project. I have an .mdb
MS Access database connected to the project. I'm using the following code to show the information of a table in a GridView
conn.Open();
OleDbCommand cmd = new OleDbCommand("SELECT Fecha, DescripciĆ³n AS Mensaje, " +
"CASE WHEN Admin = true THEN 'Admin' ELSE 'Usuario' END" +
"FROM Detalle WHERE IdParte = ? ORDER BY Fecha", conn);
cmd.Parameters.AddWithValue("IdParte", ddPartes.SelectedValue);
OleDbDataReader dr = cmd.ExecuteReader();
GridView1.DataSource = dr;
GridView1.DataBind();
conn.Close();
Details of the error I get:
System.Data.OleDb.OleDbException
HResult=0x80004005
Mensaje = Error de IErrorInfo.GetDescription con E_FAIL(0x80004005).
Origen =
Seguimiento de la pila:
You're missing a whitespace between the "END" and the "FROM". Just add it, and you should be OK:
OleDbCommand cmd = new OleDbCommand("SELECT Fecha, DescripciĆ³n AS
Mensaje, " +
"CASE WHEN Admin = true THEN 'Admin' ELSE 'Usuario' END " +
// Space added here -----------------------------------^
"FROM Detalle WHERE IdParte = ? ORDER BY Fecha", conn);
User contributions licensed under CC BY-SA 3.0