PC Review


Reply
Thread Tools Rate Thread

datatable.select("Distinct") or such to string?

 
 
=?Utf-8?B?REVXcmlnaHRfQ0FAb25saW5lLm5vc3BhbQ==?=
Guest
Posts: n/a
 
      23rd Jun 2005
I am hitting a bit of a wall - I am building a table -

public DataTable theTownships = new DataTable("AdjacentTownships");
public DataTable buildTownshipTable()
{
DataColumn tscolumn; //Townships-Range Field
tscolumn = new DataColumn();
tscolumn.DataType = System.Type.GetType("System.String");
tscolumn.ColumnName = "TSR";
tscolumn.ReadOnly = false;
tscolumn.Unique = false;
theTownships.Columns.Add(tscolumn);

return theTownships;
}

This table is built from another query where each coloumn in that row is
turned into a row here. So I can have between 1 and 0 rows, some can be
duplicates.

What I need to do is then select the distinct rows from this table and pass
them to a for loop that I can then parse/process each of the distinct rows.

Any and all suggestions would be greatly appreciated!!
--
D @ premierdata
 
Reply With Quote
 
 
 
 
=?Utf-8?B?QWRyaWFuIE1vb3Jl?=
Guest
Posts: n/a
 
      23rd Jun 2005
You might be interested in the assembly I've been working on at
http://www.queryadataset.com. Besides DISTINCT, it lets you perform complex
SQL SELECT statements including UNION, JOINS, GROUP BY, HAVING, ORDER BY,
sub-queries, etc against the tables in a dataset.

The web-site allows you to upload your own XML data fragment, DataSet or
resultset and issue queries using the QueryADataSet assembly.

Adrian Moore
http://www.queryadataset.com

---
"(E-Mail Removed)" wrote:

> I am hitting a bit of a wall - I am building a table -
>
> public DataTable theTownships = new DataTable("AdjacentTownships");
> public DataTable buildTownshipTable()
> {
> DataColumn tscolumn; //Townships-Range Field
> tscolumn = new DataColumn();
> tscolumn.DataType = System.Type.GetType("System.String");
> tscolumn.ColumnName = "TSR";
> tscolumn.ReadOnly = false;
> tscolumn.Unique = false;
> theTownships.Columns.Add(tscolumn);
>
> return theTownships;
> }
>
> This table is built from another query where each coloumn in that row is
> turned into a row here. So I can have between 1 and 0 rows, some can be
> duplicates.
>
> What I need to do is then select the distinct rows from this table and pass
> them to a for loop that I can then parse/process each of the distinct rows.
>
> Any and all suggestions would be greatly appreciated!!
> --
> D @ premierdata

 
Reply With Quote
 
=?Utf-8?B?REVXcmlnaHRfQ0FAb25saW5lLm5vc3BhbQ==?=
Guest
Posts: n/a
 
      23rd Jun 2005
Ok, that looks interesting, but how can I use it against a table I have
created in memory. Then put the data that is returned into a format that I
can feed into my for loop?

"Adrian Moore" wrote:

> You might be interested in the assembly I've been working on at
> http://www.queryadataset.com. Besides DISTINCT, it lets you perform complex
> SQL SELECT statements including UNION, JOINS, GROUP BY, HAVING, ORDER BY,
> sub-queries, etc against the tables in a dataset.
>
> The web-site allows you to upload your own XML data fragment, DataSet or
> resultset and issue queries using the QueryADataSet assembly.
>
> Adrian Moore
> http://www.queryadataset.com
>
> ---
> "(E-Mail Removed)" wrote:
>
> > I am hitting a bit of a wall - I am building a table -
> >
> > public DataTable theTownships = new DataTable("AdjacentTownships");
> > public DataTable buildTownshipTable()
> > {
> > DataColumn tscolumn; //Townships-Range Field
> > tscolumn = new DataColumn();
> > tscolumn.DataType = System.Type.GetType("System.String");
> > tscolumn.ColumnName = "TSR";
> > tscolumn.ReadOnly = false;
> > tscolumn.Unique = false;
> > theTownships.Columns.Add(tscolumn);
> >
> > return theTownships;
> > }
> >
> > This table is built from another query where each coloumn in that row is
> > turned into a row here. So I can have between 1 and 0 rows, some can be
> > duplicates.
> >
> > What I need to do is then select the distinct rows from this table and pass
> > them to a for loop that I can then parse/process each of the distinct rows.
> >
> > Any and all suggestions would be greatly appreciated!!
> > --
> > D @ premierdata

 
Reply With Quote
 
Adrian Moore
Guest
Posts: n/a
 
      24th Jun 2005
Just to clarify my understanding. You have a DataTable called
AdjacentTownships that contains a column TSR and rows which contain
duplicate data in the TSR column. You want to retrieve a distinct set of
values for the TSR column and process each row in a for loop.

Make sure the DataTable belongs to a DataSet, then using the QueryADataSet
assembly,

DataView dv = QueryADataSet.DsCommand.Execute("SELECT DISTINCT TSR FROM
AdjacentTownships" , ds);

for (int i = 0; i < dv.Count; i++)
{
DataRow dr = dv[i].Row;
// parse/process data in row
}

If you want distcint rows, then the query becomes SELECT DISTINCT * FROM
AdjacentTownships

Hope this helps
Ad.

"(E-Mail Removed)"
<(E-Mail Removed)@discussions.microsoft.com> wrote in message
news:7D758E65-E892-4170-889D-(E-Mail Removed)...
> Ok, that looks interesting, but how can I use it against a table I have
> created in memory. Then put the data that is returned into a format that I
> can feed into my for loop?
>
> "Adrian Moore" wrote:
>
>> You might be interested in the assembly I've been working on at
>> http://www.queryadataset.com. Besides DISTINCT, it lets you perform
>> complex
>> SQL SELECT statements including UNION, JOINS, GROUP BY, HAVING, ORDER BY,
>> sub-queries, etc against the tables in a dataset.
>>
>> The web-site allows you to upload your own XML data fragment, DataSet or
>> resultset and issue queries using the QueryADataSet assembly.
>>
>> Adrian Moore
>> http://www.queryadataset.com
>>
>> ---
>> "(E-Mail Removed)" wrote:
>>
>> > I am hitting a bit of a wall - I am building a table -
>> >
>> > public DataTable theTownships = new DataTable("AdjacentTownships");
>> > public DataTable buildTownshipTable()
>> > {
>> > DataColumn tscolumn; //Townships-Range Field
>> > tscolumn = new DataColumn();
>> > tscolumn.DataType = System.Type.GetType("System.String");
>> > tscolumn.ColumnName = "TSR";
>> > tscolumn.ReadOnly = false;
>> > tscolumn.Unique = false;
>> > theTownships.Columns.Add(tscolumn);
>> >
>> > return theTownships;
>> > }
>> >
>> > This table is built from another query where each coloumn in that row
>> > is
>> > turned into a row here. So I can have between 1 and 0 rows, some can be
>> > duplicates.
>> >
>> > What I need to do is then select the distinct rows from this table and
>> > pass
>> > them to a for loop that I can then parse/process each of the distinct
>> > rows.
>> >
>> > Any and all suggestions would be greatly appreciated!!
>> > --
>> > D @ premierdata



 
Reply With Quote
 
Steven Cheng[MSFT]
Guest
Posts: n/a
 
      24th Jun 2005
Hi Dewright,

For datatable retrieveing from physical DATABASE, we'll recommend doing the
filtering in the database's SQL query. For your scenario, since the
DataTable are maually created in memory on the fly, I think we may need to
do the filtering through a loop ourselve since the DataTable's buildin
select method didn't provide Distince function. Here are some articles
which discussing on doing distinct selection on .NET's DataTable manually:

#Select DISTINCT on DataTable
http://weblogs.asp.net/eporter/archi...10/370548.aspx

#HOW TO: Implement a DataSet SELECT DISTINCT Helper Class in Visual C# .NET
http://support.microsoft.com/?id=326176


Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

 
Reply With Quote
 
=?Utf-8?B?REVXcmlnaHRfQ0FAb25saW5lLm5vc3BhbQ==?=
Guest
Posts: n/a
 
      24th Jun 2005
These both look great, will give them a shot in the morning!

Once again I think you have saved my world Steven!
--
D @ premierdata


"Steven Cheng[MSFT]" wrote:

> Hi Dewright,
>
> For datatable retrieveing from physical DATABASE, we'll recommend doing the
> filtering in the database's SQL query. For your scenario, since the
> DataTable are maually created in memory on the fly, I think we may need to
> do the filtering through a loop ourselve since the DataTable's buildin
> select method didn't provide Distince function. Here are some articles
> which discussing on doing distinct selection on .NET's DataTable manually:
>
> #Select DISTINCT on DataTable
> http://weblogs.asp.net/eporter/archi...10/370548.aspx
>
> #HOW TO: Implement a DataSet SELECT DISTINCT Helper Class in Visual C# .NET
> http://support.microsoft.com/?id=326176
>
>
> Steven Cheng
> Microsoft Online Support
>
> Get Secure! www.microsoft.com/security
> (This posting is provided "AS IS", with no warranties, and confers no
> rights.)
>
>

 
Reply With Quote
 
Steven Cheng[MSFT]
Guest
Posts: n/a
 
      24th Jun 2005
You're welcome Dewright :-)

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

 
Reply With Quote
 
Cor Ligthert
Guest
Posts: n/a
 
      24th Jun 2005
Hi,

I have once made a generic routine for this, it is in VBNet however I assume
that you can translate that.

http://groups-beta.google.com/group/...8449bba5e5e1d0

I hope this helps,

Cor


 
Reply With Quote
 
=?Utf-8?B?REVXcmlnaHRfQ0FAb25saW5lLm5vc3BhbQ==?=
Guest
Posts: n/a
 
      24th Jun 2005
Steven,
I went through the MSDN Article and got the code mostly implemented.

dsHelper.SelectDistinct("thinTownships", ds.Tables["AdjacentTownships"],
"TSR");

When I try to assign my datagrid like this,
DataGrid2.SetDataBinding(ds, "thinTownships");

I get a message about WebControl.Datagrid does not contain a definition for
SetDataBinding. So I tried this,

DataGrid2.DataSource = "thinTownships";
DataGrid2.DataBind();

This code returns a table that just has the column header and it actually
put the string thinTownships vertically broken up by charecters.

Any thoughts on how I might be able to do this using a web grid?
--
D @ premierdata


"Steven Cheng[MSFT]" wrote:

> You're welcome Dewright :-)
>
> Steven Cheng
> Microsoft Online Support
>
> Get Secure! www.microsoft.com/security
> (This posting is provided "AS IS", with no warranties, and confers no
> rights.)
>
>

 
Reply With Quote
 
=?Utf-8?B?REVXcmlnaHRfQ0FAb25saW5lLm5vc3BhbQ==?=
Guest
Posts: n/a
 
      24th Jun 2005
Never you mind, I figured out how to do it, just needed to think my way
through!

Thanks again works like a charm!
--
D @ premierdata


"(E-Mail Removed)" wrote:

> Steven,
> I went through the MSDN Article and got the code mostly implemented.
>
> dsHelper.SelectDistinct("thinTownships", ds.Tables["AdjacentTownships"],
> "TSR");
>
> When I try to assign my datagrid like this,
> DataGrid2.SetDataBinding(ds, "thinTownships");
>
> I get a message about WebControl.Datagrid does not contain a definition for
> SetDataBinding. So I tried this,
>
> DataGrid2.DataSource = "thinTownships";
> DataGrid2.DataBind();
>
> This code returns a table that just has the column header and it actually
> put the string thinTownships vertically broken up by charecters.
>
> Any thoughts on how I might be able to do this using a web grid?
> --
> D @ premierdata
>
>
> "Steven Cheng[MSFT]" wrote:
>
> > You're welcome Dewright :-)
> >
> > Steven Cheng
> > Microsoft Online Support
> >
> > Get Secure! www.microsoft.com/security
> > (This posting is provided "AS IS", with no warranties, and confers no
> > rights.)
> >
> >

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
"select distinct" in Excel Gusur Microsoft Excel Discussion 3 8th Mar 2009 05:47 AM
A case sensitive version of "SELECT DISTINCT" for Jet SQL =?Utf-8?B?UHJhbW9kUw==?= Microsoft Access Queries 2 19th Jan 2007 12:38 PM
Re: "DataTable.Select(String*)" criteria Miha Markic [MVP C#] Microsoft C# .NET 0 1st Sep 2005 09:54 PM
what is the syntax for "SELECT DISTINCT column-name?" =?Utf-8?B?Sm9yZ2U=?= Microsoft Access Queries 7 26th Nov 2004 12:49 AM
How do I implement a "SELECT DISTINCT" equivalent? Danny Microsoft ADO .NET 1 9th Nov 2003 04:50 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:20 PM.