如何根据选定的行显示从数据库到网格的行 [英] How do I display rows from database to grid based on selected rows

查看:58
本文介绍了如何根据选定的行显示从数据库到网格的行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个已有数据的网格。我的要求是从网格中选择几行,并根据选定的行从数据库中获取数据并分配给同一网格的其他列。



我是什么尝试过:



我能够将数据加载到网格中。然后能够选择行并获取数据。但是无法为同一网格分配同一网格的不同属性/列。请帮助

I have a grid which already has data . My requirement is to select few rows from grid and based on selected rows get data from database and assign to the other columns of the same grid.

What I have tried:

I was able to load data to grid. Then was able to select rows and get data also. But not able to assign to same grid different property / columns of the same grid .. Please help

推荐答案

您的网格是如何设置的?



我会



a)设置bindingsource 如何:将数据绑定到Windows窗体DataGridView控件 [ ^ ]并将DataSource绑定到DataGridView



b)首先,你从数据库'表A'加载创建并加载一个DataTable'DataTable_A',然后将BindingSource.DataSource设置为'DataTable_A'



myBindingSource.DataSource = DataTable_A;



c)当你选择行并获取数据时,假设你将数据加载到一个DataTable'DataTable_B'。



d)然后你将BindingSource .DataSource更改为DataTable_B



myBindingSource。 DataSource = DataTable_B;



e)(现在,我不确定在这个阶段你有没有o强制刷新DataGridView),但是,你应该在DataGridView中有DataTable_B信息



这些是粗略的步骤 - 我认为它'可行' ,你可能需要研究一下来充实更精细的点
How is your grid set up ?

I would

a) set up a bindingsource How to: Bind Data to the Windows Forms DataGridView Control[^] and bind the DataSource to the DataGridView

b) to start with, you load create and load a DataTable 'DataTable_A' for example from Database 'Table A', and set the BindingSource.DataSource to this 'DataTable_A'

myBindingSource.DataSource = DataTable_A;

c) when you select rows and get data, lets say you load that data to a DataTable 'DataTable_B'.

d) Then you change the BindingSource .DataSource To DataTable_B

myBindingSource.DataSource = DataTable_B;

e) (now, Im not sure at this stage wether you have to force a refresh of the DataGridView), but then, you should have the DataTable_B info in the DataGridView

These are rough steps - I think its 'do-able', you may need to research a bit to flesh out the finer points


这篇关于如何根据选定的行显示从数据库到网格的行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆