Thursday, February 16, 2012

[ask] how to invoke sqldatasource command in method?

hello everybody, i have a question to ask,

suppose i have a sqldatasource, can i use it in a method??

this is my case, i need to make a new method to count the rows in a datagrid, so i will have to read the sqldatasource. the problem is, how to retrieve it?? usually i use the built in sqldatasource_selected to count the rows...

is there any other way??

Lets have a binddata method

privatevoid BindData()

{

SqlDataSource1.SelectCommand =

"Select * from clients";

}

Call the above method in PageLoad or any other desired Event

In theSqlDataSource1_Selected

retrive the total rows

protectedvoid SqlDataSource1_Selected(object sender,SqlDataSourceStatusEventArgs e)

{

Label1.Text = e.AffectedRows.ToString();

}

Hope this will help you.

let me know if need further clarifications

|||

yupz i know that, but that doesn't solve my problem

if i save the total row to a variable, let's say countRow = e.AffectedRows, how can i pass this value to another method??

(i need this value to be added by 1 so i can use it for the next primary key)

|||

Store it in a Viewstate or Session Variable

Set Value

Session[

"RowCount"] = e.AffectedRows;

ViewState[

"RowCount"] = e.AffectedRows;

Getvalue

int rowCount1 =int.Parse(Session["RowCount"].ToString());

int rowCount2 =int.Parse(ViewState["RowCount"].ToString());

If you need to access the value even in otherpage use Session or Viewstate itself ok

|||

oww yes, session variable...i completely forget it :)

thx so much bro...

but that viewstate variable...what is the difference??

btw thx so much bro

|||

The values stored in session will be available through out the Session of a particular user irrespective of the page he/she is navigating.

Value stored in viewstate will be available only in the page in which it have been set.

More over in Viewstate you can place only string ,in Session variable you can place any object

Have a look into these links

http://hiltong.blogspot.com/2004/11/viewstate-vs-session-state-vs.html

http://aspalliance.com/articleViewer.aspx?aId=135&pId=

Hope this will help you

|||well...thank you very much bro

No comments:

Post a Comment