Showing posts with label distinct. Show all posts
Showing posts with label distinct. Show all posts

Thursday, March 29, 2012

Getting a row count from a DataSource vs GridView

There HAS to be an easier way to do this...

I have 2 seperate SqlDataSources for 2 distinct filters. How do I get a simple row count for each SqlDataSource? It seems the only way is by using the ObjectDataSource and going through that whole mess (paging, etc.). And unfortunately, you can't simply get the number of rows in the GridView that represents each DataSource if AllowPaging is true for the GridView.

This is frustrating.

Dave

You gotta setup the Selected Event

protected void SqlDataSource1_Selected( object sender, SqlDataSourceStatusEventArgs e )
{
e.AffectedRows;
}

|||

Can you give me a little more insight...

Thanks,

Dave

|||

Not sure how much more detailed I can get. When you setup your SqlDataSources, put

<asp:SqlDataSourceID="SqlDataSource1"runat="server"OnSelected="SqlDataSource_Selected" ... />
<asp:SqlDataSourceID="SqlDataSource2"runat="server"OnSelected="SqlDataSource_Selected".../>

They both should be able to use the same event since you want them both to do the same thing.

Then in your code-beside, setup the event as follows

protectedvoid SqlDataSource_Selected(object sender,SqlDataSourceStatusEventArgs e )
{
// Do something with e.AffectedRows
Response.Write( e.AffectedRows );
}

Sunday, February 19, 2012

Get only Max of each distinct?

Hello,

I have a table

ItemID Version

12 1.0
12 1.1
12 2.0
13 2.0
13 1.0
14 1.0
15 1.0
15 5.0
15 2.1

How do I write a Select query to get me all distinct item IDs, whichm
are of the latest version?

Like this:

ItemID Version
12 2.0
13 2.0
14 1.0
15 2.1

Any help would be appreciated.

Thankssunilkes@.gmail.com wrote:

Quote:

Originally Posted by

I have a table
>
ItemID Version
>
12 1.0
12 1.1
12 2.0
13 2.0
13 1.0
14 1.0
15 1.0
15 5.0


I assume 5.0 is a typo for 2.0

Quote:

Originally Posted by

15 2.1
>
How do I write a Select query to get me all distinct item IDs, whichm
are of the latest version?
>
Like this:
>
ItemID Version
12 2.0
13 2.0
14 1.0
15 2.1


This smells like homework. Look up MAX() and GROUP BY.|||On Nov 7, 10:10 am, Ed Murphy <emurph...@.socal.rr.comwrote:

Quote:

Originally Posted by

sunil...@.gmail.com wrote:

Quote:

Originally Posted by

I have a table


>

Quote:

Originally Posted by

ItemID Version


>

Quote:

Originally Posted by

12 1.0
12 1.1
12 2.0
13 2.0
13 1.0
14 1.0
15 1.0
15 5.0


>
I assume 5.0 is a typo for 2.0
>


Got it, actually it was pretty simple, was trying it incorrectly
earlier !

SELECT MAX(Version_Number) AS Maxim, ItemId
FROM tblItems
GROUP BY ItemId

Thanks

Quote:

Originally Posted by

Quote:

Originally Posted by

15 2.1


Quote:

Originally Posted by

>

Quote:

Originally Posted by

How do I write a Select query to get me all distinct item IDs, whichm
are of the latest version?


>

Quote:

Originally Posted by

Like this:


>

Quote:

Originally Posted by

ItemID Version
12 2.0
13 2.0
14 1.0
15 2.1


>
This smells like homework. Look up MAX() and GROUP BY.