本文介绍了在gridview数据库值中检索并使用C#显示到gridview中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 从房间中选择RoomNo,Minor_Code,其中active ='A',Dateofcrs ='1/7/2013',Sess ='PM'; 输出为以下查询 房间课程 11 EFA 22 PST 23 PH2 31 AFF 32 PSCRB 34 TFC 我的网格视图如下 房间课程房间课程房间课程 11 21 31 12 22 32 13 23 33 14 24 34 in gridview,用于从数据库中检索并根据Room显示在gridview中的课程。 我想要输出如下在gridview中(cour se name从数据库中检索出来) 房间课程房间课程房间课程 11 EFA 21 31 AFF 12 22 PST 32 PSCRB 13 23 PH2 33 14 24 34 TFC 我该怎么办?使用csharp。 Rgds, Narasiman P. select RoomNo,Minor_Code from room where active = 'A' and Dateofcrs = '1/7/2013' and Sess = 'PM';Output as follows for the above query Room Course 11EFA 22PST 23PH2 31AFF 32PSCRB 34TFC My gridview as follows Room Course Room Course Room Course 11 21 31 12 22 32 13 23 33 14 24 34in the gridview, for the course that to be retrieved from the database and display in to the gridview according to Room.I want output as follows in the gridview(course name is retrieved from the database) Room Course Room Course Room Course 11 EFA 21 31 AFF 12 22 PST 32 PSCRB 13 23 PH2 33 14 24 34 TFCfor that how can i do using csharp.Rgds,Narasiman P.推荐答案 基本上你有一个代表教室的桌子,你想要显示每个房间都有哪些课程......对吗? 最简单的方法是创建一个DataTable,它将成为网格的数据源,并在匹配现有房间和查询结果时正确填充。 创建2个循环4并建立你的表validati如果每个房间号都在查询结果上,如果是,请添加课程名称。Basically you have a table that represent class rooms and you want to show which courses are being given on each room... correct?The easiest thing is to create a DataTable that will be the datasource of your grid and fill it properly matching the existing rooms and the result of the query.Create 2 loops of 4 and build your table validation if each room number is on the query result, if so, add the course name. Concider DT as ur grid DataSourse, 将您选择的查询结果添加到集合中... Concider DT as ur grids DataSourse,Add your select querie's result to a collection...DataTable DT = new DataTable(); Dictionary<int, string> dic = new Dictionary<int, string>(); string course = ""; foreach (DataRow r in DT.Rows) { if (dic.TryGetValue(r[0], out course)) { r[1] = course; } if (dic.TryGetValue(r[2], out course)) { r[3] = course; } if (dic.TryGetValue(r[4], out course)) { r[5] = course; } } 希望它有效.. Hope it works.. 这篇关于在gridview数据库值中检索并使用C#显示到gridview中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 10-27 14:00