3, database base class, the Query method return value is List<t>, and is paged, ThePart.dll version 2.0 encapsulates a PageInfo class, as the type of paging. This method is very mechanical, also very dog blood. We recommend that you do not use this, the following example is written by colleagues in the project. In order to database the base class of the operation of databases return values of various types, so that people know that all kinds of data can be processed. For such a purpose, I would like to post the example. I hardly ever bother to look at it myself.
public static list<sportsbetrecords> Sportsgetlistpager (String Saleid, String UserName, string status, string ClassType, String startime, string EndTime, int? pSize, int? Pindex, out int count)
{
PSize = pSize?? 10; Maximum number of records per page
Pindex = Pindex?? 1; Current page
Pagerinfo pager = new Pagerinfo (); ThePart.dll in the package of such a paging class Pagerinfo
Pager. ProcName = "pr_pager2005"; Stored procedures for the required database
Pager. Tablenames = "Sportsbetrecords"; database table names that need to be manipulated
Pager. PageSize = (int) pSize; Maximum number of records
Pager. currentpage = (int) pindex; Current page
StringBuilder sb = new StringBuilder ("1=1 and saleid= '" + Saleid + "'"); Conditions for variable strings
if (!string. IsNullOrEmpty (UserName))
Sb. Append ("and username=" + UserName + "'");
if (!string. IsNullOrEmpty (startime) &&!string. IsNullOrEmpty (EndTime))
Sb. Append ("and [T] between '" + convert.todatetime (startime) + "' and '" + convert.todatetime (EndTime). AddDays (1) + "'");
Pager. Condition = sb. ToString (); The condition after where in SQL
Pager. Count = 1;
Pager. Fields = "*";
Pager. IndexName = "Id";
Pager. Ordernames = "[T] desc";
list<sportsbetrecords> recordlist = ormbase.getlist<sportsbetrecords> (ref pager);
Count = Pager. Count;
return recordlist;
}
The following is the corresponding stored procedure:
Use [Casino]
GO
/****** object:storedprocedure [dbo]. [pr_pager2005] Script date:05/13/2014 15:05:28 ******/
SET ANSI_NULLS on
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo]. [pr_pager2005]
(
@TableNames VARCHAR (4000),--table name
@Fields VARCHAR (1000) = ' * ',--the column that needs to be returned (cannot have the same field, if there is the same field, the first outside of the other fields can be converted to aliases, such as: b.ID as BID)
@Condition VARCHAR (1500) = ",--query criteria
@IndexName VARCHAR = ' ID ',--Primary index field (void here, only compatible)
@PageSize INT = 20,--Number of records per page
@CurrentPage INT = 1,--current page number
@OrderNames VARCHAR (50) = ',--sort field, to include sort type
@OrderType BIT = 1,--sort type, 0-Descending 1-Ascending (default) (void here, only compatible)
@Count Int=null OUTPUT,
@Distinct VARCHAR (9) = ",--to repeat the record Distinct
@GroupBy VARCHAR (100) = ",
@TSQL NVARCHAR (4000) = ' OUTPUT--The TSQL statement that was executed or the TSQL that was executed prior to paging
)
As
DECLARE @SQL NVARCHAR (max)--the subject sentence
DECLARE @OrderBy VARCHAR (300)--sort
DECLARE @StartRow int, @ENDRow int
SET @SQL = ' '
BEGIN
SET NOCOUNT on
IF (@CurrentPage <1)
SET @CurrentPage = 1
SET @StartRow = (@CurrentPage-1) * @PageSize +1
SET @ENDRow = @CurrentPage * @PageSize
IF (@Condition! = ")
SET @Condition = ' Where ' + @Condition
IF (@GroupBy! = ")
SET @GroupBy = ' Group by ' + @GroupBy
IF (@Distinct! = ")
SET @Distinct = @Distinct + "
IF (@OrderNames = ")
SET @OrderBy = ' '
ELSE
SET @OrderBy = ' Order by ' + @OrderNames
IF (@Count is not null) and @Count > 0)
BEGIN
IF (@GroupBy = ")
SET @SQL = @TSQL + ' Select ' [email protected]+ ' @c=count (0) from ' + @TableNames + @Condition
ELSE
SET @SQL = @TSQL + ' SELECT ' [email protected]+ ' @c=count (0) from (Select 0 as ID from ' + @TableNames + @Condition + @G Roupby + ') as T '
EXEC sp_executesql @SQL, N ' @c INT output ', @Count output
END
--The following implements the case with group by and without group by
IF (@GroupBy = ")
Begin
SET @SQL = @TSQL + ' with T1 as (Select ' + @Distinct + @Fields + ', row_number () over (' + @OrderBy + ') as RowNo from ' + @TableNames + @Condition + ') '
SET @SQL = @SQL + ' Select * from T1 Where RowNo between ' + cast (@StartRow as varchar) + ' and ' + cast (@ENDRow as varchar )
END
ELSE
Begin
SET @SQL = @TSQL + ' with T1 as (Select ' + @Distinct + @Fields + ' from ' + @TableNames + @Condition + @GroupBy + ') '
SET @SQL = @SQL + ' SELECT * FROM (select *,row_number () over (' + @OrderBy + ') as RowNo from T1) as T2 Where RowNo between ' + CAST (@StartRow as varchar) + ' and ' + cast (@ENDRow as varchar)
END
END
EXEC (@SQL)
4. Return all list table records directly: No query conditions and write SQL statements are required. The entity class. getlist< Solid class > (0)
public static list<betresultinfo> Betrinfo ()
{
Return betresultinfo.getlist<betresultinfo> (0);
}
5. Update the value of the Data table field: entity class. Update (Instance object of the entity, field value to modify)
public static int Update (W88betrecords item)
{
Return W88betrecords.update (item, "id=" + item.) Id.value + "and terraceid=2");
}
6, a single value is queried, the value is an Object Type: entity class. Execsqlobj ("Database name", "Full SQL statement", New object[]{});
<summary>
Query the range of limit values by rank ID
</summary>
<param name= "Gradeid" ></param>
<returns></returns>
public static string Getregardbyid (int gradeid)
{
String sql = "Select Limitvalue from Regard where gradeid=" + Gradeid;
Return convert.tostring (Regard.execsqlobj ("Casino", SQL, new object[] {}));
}