查找和显示与从数据库到Datagridview的键(非主键)相关的行 [英] Finding and displaying rows related to a key(not a primary key) from database to datagridview

查看:83
本文介绍了查找和显示与从数据库到Datagridview的键(非主键)相关的行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以找到一些与字段相关的选定行(即数据库中存在的行)并将其显示在DataGridView中? 简单来说,对于跟随ADO连接的代码,Ado断开连接中的等效代码是什么

Is it possible to find some selected rows related to a field(i.e. present in the database) and display it in DataGridView ???
simply, for following ADO connected code, what will be the equivalent code in Ado disconnected

SqlCommand cmd = new SqlCommand("select * from employee where department=@department", c);
cmd.Parameters.AddWithValue("department", @department);
    SqlDataReader dr = cmd.ExecuteReader();

部门"的值将通过文本框传递.
部门"不是主键.

value of "department" will be passed through textbox.
"department" is not primary key.

推荐答案

一种方法是,根据查询填充数据表并将该数据表分配给datagridview的DataSource.

例如,请参阅: http://msdn.microsoft.com/en -us/library/system.windows.forms.datagridview.datasource.aspx [ http ://msdn.microsoft.com/zh-CN/library/905keexk.aspx [ ^ ]
One way is that you fill a datatable based on your query and assign that datatable to the DataSource of the datagridview.

For example, see: http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridview.datasource.aspx[^] and http://msdn.microsoft.com/en-us/library/905keexk.aspx[^]


这篇关于查找和显示与从数据库到Datagridview的键(非主键)相关的行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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