Showing posts with label suppose. Show all posts
Showing posts with label suppose. Show all posts

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

Monday, February 13, 2012

[*-)] About Auto Increment Field

Hi,

I have one Auto increment field in the table.

I have a problem that suppose I have 10 Records in the table, Now If someone delete record no 3 and 5 then it has 8 records.

But The field will give 11 no to new record I want it first fill 3 and 5 then give 11 to the new record.

Is it possible with the auto increment field in sql server 2005.

No it's not possible with autoincrement fields. You would have to create your own primary key field, and query the table to get the lowest available number everytime you performed an insert. I would never recommend doing this. It's a potential nightmare, and I can't think of one single good reason for doing it. All you need is a unique identifier for each row. It doesn't matter if it's not nice and pretty (in terms of a sequential series), so long as it works.