使用DataAdapter,dataGridview,DataView,DataSet [英] using DataAdapter,dataGridview,DataView,DataSet

查看:134
本文介绍了使用DataAdapter,dataGridview,DataView,DataSet的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

现在我正在使用ADO.Net概念开发一种Windows窗体应用程序.

在这里,我创建了两个组合框,一个是datagidview.
在第一个组合框中,在连接字符串中显示Alla可用表在数据库中的字符串,并
如果第一个组合框选择Emp表,则在第二个组合框中显示部门编号.

现在,如果用户从第一个组合框中选择Emp,则在第二个组合框中显示所有部门编号.

现在,如果用户选择任何部门名称,那么必须在datagrid视图中显示该所选部门编号下的所有emplyoees
但是问题在于,当用户从第一个组合框列表中选择表时,datagrid视图中显示的所有雇员r,但是当用户在第二个组合框中选择deptno时,它不会显示相应的雇员详细信息. >解决方案



此处dgv-> DataGridView

//将值从DataGridView获取到DataTable
DataTable dtData =(DataTable)dgv.DataSource;

//过滤特定ID值
字符串sEmployeeId = 5;
字符串sCondition ="EmpId =""+ sEmployeeId +";
DataRow [] drData = dtData.Select(sCondition);

//将值设置到另一个DataTable
DatatTable dtOutput = new DataTable();
dtOutput = dtData.Clone();
foreach(drData中的DataRow dr)
{
dtOutput.ImportRow(dr);
}

dgv.DataSource = dtOutput;

我认为它的工作.如果有任何疑问要问我.
干杯...;)


sKumarn

我认为不要清除数据集值.因为它仅填充到datagridview中.

//只需检查条件
if(dgv.DataSource!= null)
{

//将值从DataGridView获取到DataTable
DataTable dtData =(DataTable)dgv.DataSource;
.
.
.
.
.
}

谢谢,
现在,您检查一下.


now i am developing one windows form appplication by using ADO.Net concept .

Here i had created two comboboxes,one datagidview .
In the First Combobox displays Alla available tables in a database in the connection string and
in the second combobox it displays department numbers if first combobox select Emp table .

Now if user select Emp from 1st combobox then in second combobox it displays all department numbers.

Now if the user selects any deptno then all emplyoees which r under that selected department number must bew displayed in the datagrid view
But problem is that when user selects table from first combobox list all the employees r displayed in the datagrid view but when user selects deptno in the second combobox it doesnot displays ciressponding employees details Give me the solution for this plroblem.

解决方案

Hi,

Here dgv -->DataGridView

// Get the Value from DataGridView to DataTable
DataTable dtData=(DataTable)dgv.DataSource;

// Filter Particular Id Value
string sEmployeeId=5;
string sCondition= "EmpId =''"+sEmployeeId+"";
DataRow[] drData=dtData.Select(sCondition);

//Set the Value into another DataTable
DatatTable dtOutput=new DataTable();
dtOutput=dtData.Clone();
foreach(DataRow dr in drData)
{
dtOutput.ImportRow(dr);
}

dgv.DataSource=dtOutput;

I think its work.If any queries ask to me.
Cheers... ;)


Hi sKumarn

I think don''t clear the dataset value.Because its only fill into datagridview.

//Just Check the Condition
if(dgv.DataSource!=null)
{

// Get the Value from DataGridView to DataTable
DataTable dtData=(DataTable)dgv.DataSource;
.
.
.
.
.
}

Thanks,
Now u check it.


这篇关于使用DataAdapter,dataGridview,DataView,DataSet的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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