newbie: getting SQL RecordCount using AffectedRows

B

Beemer Biker

I am using GridView (with paging) and SqlDataSource and there seems no
direct way to get a RecordCount. OK, it seems that SelectedEvent returns
RowsAffected. Sure enough, a breakpoint shows the record count that I want.
Looks like this would work, but something is amiss in the postback event
order as I am getting the previous sql "count" and not the current one.

If I set a breakpoint on the SelectedEvent, it does not get control (and set
the variable nRecordCount) till after I have added nRecordCount to my
infobox. The code to add that variable is in the WebControlButton.

How do I organize my code such that clicking on the button that executes the
sql command gets the record count for the SelectCommand it issued the bind
for? Clearly the following is not working as the event order is wrong.

protected int RunSelectAcq(string sqlcmd)
{
GridView4Acquisition.DataSourceID = SqlDS_ViewAcquisition.ID;
SqlDS_ViewAcquisition.SelectCommand = sqlcmd;
SqlDS_ViewAcquisition.DataBind();
return nViewAcqRecords; // always gets previous value
}

protected void SqlDS_ViewAcquisition_Selected(object sender,
SqlDataSourceStatusEventArgs e)
{
nViewAcqRecords = e.AffectedRows;
}

=========another suggestion that didnt work======
I googled around and saw a suggestion was to use DataSet (DataTable). OK, I
understand that, but bringing up ComponentDesigner, there is no DataTable
object. I do see a DataSet wizard but when i run it there is nothing to
select for input to the wizard.

Yes, I do have SqlCommand on the ComponentDesigneer and can get a "Count"
returned, but that seems a waste of resources since SqlDataSource runs a
command and sets AffectedRows and I should be able to get the values.

I assume I am not using the AutoPostBack correctly and the value is not
available when I think it is.


--
=======================================================================
Beemer Biker joestateson at grandecom dot net
http://TipsForTheComputingImpaired.com
http://ResearchRiders.org Ask about my 99'R1100RT
=======================================================================
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,189
Latest member
CryptoTaxSoftware

Latest Threads

Top