I’m having problem with my sql query.
SqlConnection conn = new SqlConnection();
conn.ConnectionString = "Data Source=.\\SQLExpress;" + "Trusted_Connection=True;" + "User Instance=True;" + "AttachDbFilename=|DataDirectory|\\fbi.mdf;";
string sqlQuery4 = "SELECT Car FROM tbl1 JOIN tbl2 ON (tbl1.userID = tbl2.userID) WHERE tbl2.username='Bob'";
SqlCommand cmd4 = new SqlCommand(sqlQuery4, conn);
conn.Open();
SqlDataReader rd = cmd4.ExecuteReader();
rd.Read();
ddl1.Items.Add(rd.GetValue(0).ToString());
conn.Close();
So it should return all cars from tbl1 that belongs to Bob. Query only return one string and put it into Listbox “ddl1” while it should return at least 3 of them.
Any ideas?
You need to loop through the reader: