I use the following statement:
string strconn = System.Configuration.ConfigurationSettings.AppSett ings["ConnectionString"].ToString();
SqlConnection conn = new SqlConnection(strconn);
string fillcmd = "SELECT Course.Name , Course.Type , Course.Points" + " " +
"FROM StudyPoints INNER JOIN Course ON StudyPoints.Study_uno = Course.Study_uno" + " " +
"WHERE StudyPoints.Trainee_uno = (select Trainee_uno from Trainees where dbo.Trainees.lastname = '" + txt_search.Text + "'" + " " +
"or dbo.Trainees.Firstname = '" + txt_search.Text + "'" + " " +
"or dbo.Trainees.Firstname + ' ' + dbo.Trainees.Lastname like '%" + txt_search.Text + "%')";
SqlDataAdapter da = new SqlDataAdapter(fillcmd, conn);
DataSet ds = new DataSet();
da.Fill(ds, "Course");
//binds the listbox with the study the trainee has followed
lstb_course.DataSource = ds;
lstb_course.DisplayMember = "Course.Name";
lstb_course.ValueMember = "Course.Type";
lstb_course.DataBindings.Add(new Binding("Text",ds,"Course.Name"));
lstb_course.DataBindings.Clear();
|