c# - How to store value of SqlDataReader in an array? -
the course_id inside while loop have multiple values. wanted display values in gridview, last value being displayed. how can that? have store course_id in array?
int course_id=0; string query_select_course = "select course_id course_program program_id = '" + program_id + "' "; sqldatareader dr_course = dataaccess.selectdatareader(query_select_course); while (dr_course.read()) { course_id = (int)dr_course.getvalue(0); // course_id should have multiple values. } dr_course.close(); string query_select_course_name = "select course_title courses course_id = '" + course_id + "' "; datatable dt = dataaccess.selectdata(query_select_course_name); course_datagridview.datasource = dt;
make list<int>
, add values in it.
list<int> course=new list<int>(); while (dr_course.read()) { course.add((int)dr_course.getvalue(0)); }
Comments
Post a Comment