Friday 15 May 2015

c# - Display Lesson Names instead of Lesson Codes in the grid with BindingSource or with some other method -



c# - Display Lesson Names instead of Lesson Codes in the grid with BindingSource or with some other method -

i have info in database. , read info , display in grid. utilize dataset, sqldataadapter, bindingsource , datagridview. table below.

+---------+------------+-------------+ | name | surname | lesson_code | +---------+------------+-------------+ | joe | black | 110 | | mia | sommers | 120 | | hasan | almalik | 100 | | anna | volkova | 100 | | robert | jackson | 115 | | tony | bernard | 120 | | diana | albert | 115 | | tom | bruce | 110 | +---------+------------+-------------+

i read info table sql query.

string sql = "select name, surname, lesson_code lesson class" sqldataadapter adapter = new sqldataadapter(); sqlcommand selectcommand = new sqlcommand(sql,connection); adapter.selectcommand = selectcommand; dataset ds = new dataset(); adapter.fill(ds,"class"); bindingsource bs = new bindingsource(ds,"class"); gridclass.datasource = bs;

ok. there not problem. dont want show lesson codes in grid. have list of lessons , lesson codes.

100 - math 110 - geometry 115 - biological science 120 - astronomy etc.

i dont store list in database. if store list in table can solve problem sql query table joining. dont want this. dont want utilize sql query. want code. think can solve problem bindingsource. dont know how? or may there way?

if saying have table lesson names associated codes have join. query should this.

select a.lesson_name, b.surname, b.name lessontable a, class b a.lesson_code = b.lesson_code

c# sql data-binding datagridview

No comments:

Post a Comment