Showing posts with label sqldatasource. Show all posts
Showing posts with label sqldatasource. Show all posts

Monday, February 27, 2012

how can i get to rows five to ten in my table?

I need to pull out rows five to ten with my sqlDataSource. is this possible?

If you are using SQL Server (Express) 2005, you can use theRow_Number function

|||

How do i use this. is it easy? CAN I WRITE sql DIRECT TO THE SQLDATASOURCE?

|||

Here is a sample:

<asp:SqlDataSourceID="SqlDataSource1"Runat="server"SelectCommand="SELECT ProductID, ProductName, CategoryID FROM (SELECT ProductID, ProductName, CategoryID, ROW_NUMBER() OVER(ORDER BY [ProductID] ASC) as rowNum FROM Products) t WHERE rowNum>4 and RowNum<=10"ConnectionString="<%$ ConnectionStrings:NWConnectionString %>">

</asp:SqlDataSource>

<asp:GridViewID="GridView1"runat="server"DataSourceID="SqlDataSource1"AutoGenerateColumns="False"DataKeyNames="ProductID">

<Columns>

<asp:BoundFieldDataField="ProductID"HeaderText="ProductID"InsertVisible="False"

ReadOnly="True"SortExpression="ProductID"/>

<asp:BoundFieldDataField="ProductName"HeaderText="ProductName"SortExpression="ProductName"/>

<asp:BoundFieldDataField="CategoryID"HeaderText="CategoryID"SortExpression="CategoryID"/>

</Columns>

</asp:GridView>

|||

Thanks. That worked!!

Friday, February 24, 2012

How Can I get hte return_Value?

Hi all~~~

I had used sqlDataSource + SQLserver procedure

The procedure like this:

...................

BEGIN

SELECT * FROM xxx

RETURN 1

END

er~~~How can I get the return_value with sqlDataSource ??

Create a parameter, and set the Direction property to ReturnValue|||Create a parameter??Would you make an example? Thanks~~|||

SqlConnection cn =newSqlConnection(MyConnectionString);

SqlCommand cmd =newSqlCommand("spName", cn);

cmd.CommandType =CommandType.StoredProcedure;

SqlParameter prm=new SqlParameter("@.ReturnValue");

prm.Direction=ReturnValue;

cmd.Parameters.Add(prm);

// Now .ExecuteNonQuery, ExecuteReader, etc. on the command.

|||Hidouglas.reilly ~It without SqlDataSourc......