I'm trying to use the existing Stored Procedure , Here i need to present only TOP 1 row which is in Dataset.
If it is not possibe then i will go for creating seperate Stored Procedure for this.
So Table 1 Is Parent Table and Table 2 is Child Table I need to give Relation to both. I need to remove Extra Columns From
Table 2 I need to keep only same column as Table 1
I.e in Table 2 I need to Keep only this result
Name Dept EMpId Location
Ajay IT 6555 Hyd
Is it possible to Sort this out from Code Behind? Can some one help me please
In fact I think you can just use an "inner join" statement to link the two tables together and then fetch the result by linking the two fields together,you don't need to use DataSet by filling two tables:
using(SqlDataAdapter adapter = new SqlDataAdapter("select Top 1 Table2.* from Table1 inner join Table2 where Table1.Dept=Table2.Dept"))
{
DataTable dt = new DataTable();
adapter.Fill(dt);
}
aparitala
Member
13 Points
83 Posts
How to Select Top 1 row from Data set
Nov 21, 2012 01:21 PM|LINK
Hello,
Can someone help me!
How to select Top1 Row from a Dataset in c#.net ?
urenjoy
Star
12193 Points
1825 Posts
Re: How to Select Top 1 row from Data set
Nov 21, 2012 01:30 PM|LINK
DataRow firstRow = MyDataset.Tables[0].Rows[0];
OR
you can use LINQ and bind to gridview, try following
aparitala
Member
13 Points
83 Posts
Re: How to Select Top 1 row from Data set
Nov 21, 2012 02:16 PM|LINK
Hi Again,
How to convert DataRow to Dataset and how to bind that Dataset to Gridview...
urenjoy
Star
12193 Points
1825 Posts
Re: How to Select Top 1 row from Data set
Nov 21, 2012 02:30 PM|LINK
you can use LINQ and bind to gridview, try following
aparitala
Member
13 Points
83 Posts
Re: How to Select Top 1 row from Data set
Nov 21, 2012 04:59 PM|LINK
Hi Thank You....!
But our server is in vs2005 it doesn't support LinQ :(
So any alternate?
RameshRajend...
Star
7983 Points
2099 Posts
Re: How to Select Top 1 row from Data set
Nov 21, 2012 05:26 PM|LINK
Hai
try this
But its not a good logic.But try this
Pass DataViewValue and Row count
public static DataView SelectTopFrom(DataView dv, int rowCount) { DataTable dt = CreateTable(dv); DataTable dtn = dt.Clone(); for (int i = 0; i < rowCount; i++) { dtn.ImportRow(dt.Rows[i]); } DataView dvn = new DataView(dtn); return dvn; }Thank yow
Dan Bracuk
Contributor
3970 Points
1096 Posts
Re: How to Select Top 1 row from Data set
Nov 21, 2012 05:30 PM|LINK
I've never tried it, but can't you simply bind the Gridview to the DataRow.
aparitala
Member
13 Points
83 Posts
Re: How to Select Top 1 row from Data set
Nov 21, 2012 05:54 PM|LINK
Hi,
I'm trying to use the existing Stored Procedure , Here i need to present only TOP 1 row which is in Dataset.
If it is not possibe then i will go for creating seperate Stored Procedure for this.
Thank You...!
aparitala
Member
13 Points
83 Posts
Re: How to Select Top 1 row from Data set
Nov 21, 2012 06:59 PM|LINK
Hi is it possible?
In Dataset I'm getting two Tables
in Table 1 I have these results Say
Name Dept
Ajay IT
In second Table
Name Dept EMpId Location
Ajay IT 6555 Hyd
Xyz IT-IS 544 Vj
So Table 1 Is Parent Table and Table 2 is Child Table I need to give Relation to both. I need to remove Extra Columns From Table 2 I need to keep only same column as Table 1
I.e in Table 2 I need to Keep only this result
Name Dept EMpId Location
Ajay IT 6555 Hyd
Is it possible to Sort this out from Code Behind? Can some one help me please
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: How to Select Top 1 row from Data set
Nov 23, 2012 12:24 AM|LINK
In fact I think you can just use an "inner join" statement to link the two tables together and then fetch the result by linking the two fields together,you don't need to use DataSet by filling two tables:
using(SqlDataAdapter adapter = new SqlDataAdapter("select Top 1 Table2.* from Table1 inner join Table2 where Table1.Dept=Table2.Dept")) { DataTable dt = new DataTable(); adapter.Fill(dt); }