C# 用多个数据源填充数据网格的问题
嘿朋友们我的程序中有 datagridview 。我需要从数据库填充数据网格,但一列,即名为“TIME”的列,我必须从同一表单中存在的日期时间选择器中填充它。 在 LOAD 按钮中,当我单击它时,datagridview 应该填充数据库中的记录以及名为 TIME 的列中的数据时间选择器的值。所以如果有人发送解决方案,我将非常感激。
HEy Friends I have datagridview in my program. I need to fill datagrid from database but One column i.e, named "TIME" i have to fill it from the datetime picker present in same form.
There in LOAD button, when i click it, datagridview should be populated with records from database along with the value of datatime picker in the Column named TIME. so i will be very thankful if anyone send the solution.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以将 datetimepicker 值设置为 sqlcommand,如下所示:
请测试一下。我认为它比向数据表添加新列并在数据表填充后将其值设置为 datetimepicker.value 更快
you can set datetimepicker value to sqlcommand as below:
test it please. And i think it will faster than adding new column to datatable and set its value to datetimepicker.value after datatable filled
如果您使用 DataSet/DataAdapter 绑定 Grid,则可以按如下方式执行此操作:
You can do this as follows if you are using DataSet/DataAdapter to bind the Grid:
我认为您可以使用数据绑定事件来添加额外的列。根据您的框架版本和网格类型(Datagrid 或 Gridview),事件略有不同。
基本思想是,每次将一行添加到网格中并且您动态地将自己的值添加到您指定的另一列时,都会调用该事件。抱歉,我无法提供更多信息,但根据您所提供的内容,我只能提供这些了。
I think you could use the data binding events to add your extra column. Depending on your framework version and type of grid (Datagrid or Gridview) the events differ slightly.
The basic idea is the event is called each time a row is added to the grid and you dynamically add your own value into another column you specify. Sorry I can't offer more than this but it's all I can based on what you've presented.