I am trying to get the results of the query below and display it in a listBox but I keep getting this error : Syntax Error near 'a'. Here is my code:
SqlConnection con = new SqlConnection(@"Data Source=JOHZZ\SQLEXPRESS;
Persist Security Info=True;
SqlCommand c3 = new SqlCommand("SELECT targa" +
"FROM mjete AS m INNER JOIN abonimi_mjet AS a" +
"ON m.mjeti_id = a.mjeti_id" +
"WHERE a.statusi = 'PASIV'" +
"AND m.klient_id = @idK", con);
SqlDataReader reader2 = c3.ExecuteReader();
You need a space between your lines. Using the + symbol adds them together as one string, just add a space at the end of each string.
SqlCommand c3 = new SqlCommand("SELECT targa " + "FROM mjete AS m INNER JOIN abonimi_mjet AS a " + "ON m.mjeti_id = a.mjeti_id " + "WHERE a.statusi = 'PASIV' " + "AND m.klient_id = @idK", con);
What you have now results in this string as the line breaks in your c# file are not string line breaks.
"SELECT targaFROM mjete AS m INNER JOIN abonimi_mjet AS aON m.mjeti_id = a.mjeti_idWHERE a.statusi = 'PASIV'AND m.klient_id = @idK"
You should wrap your
SqlConnection instance in a
using block to ensure it is always closed/disposed when you are done using it (even in the event of an Exception). The same goes for your