Saturday, September 27, 2008
Get control name in Page_Load event which make the post back
http://geekswithblogs.net/mahesh/archive/2006/06/27/83264.aspx
Wednesday, September 17, 2008
Change Display Order in Table using Sql
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Project : VirSanghvi
-- Procedure Name : [usp_Admin_DisplayOrder_ChangeDisplayOrder]
-- Author: Rajat
-- Create date: 17-Sep 2008
-- Description: updating the Forum Post
-- Modified By :
-- Modification Date:
-- =============================================
--usp_Admin_DisplayOrder_ChangeDisplayOrder 'Tbl_Article','ArticleID',1,3,''
-- select * from Tbl_ForumPost
ALTER PROCEDURE [dbo].[usp_Admin_DisplayOrder_ChangeDisplayOrder]
@TableName varchar(100),
@FieldName varchar(100),
@ID varchar(10),
@CurrentDisplayOrder varchar(10),
@Level varchar(100)
AS
DECLARE @RetVal INT,@strSql varchar(5000),@strSqlNew varchar(5000),@strSqlNew1 varchar(5000),@oDisplayOrder varchar(50)
SET @RetVal = -1
SET @strSql =''
SET @strSqlNew=''
SET @strSqlNew1=''
BEGIN TRY
--BEGIN TRAN
CREATE TABLE #TempDisplayOrder (
DisplayOrder varchar(50) )
IF(@Level <> '')
BEGIN
SET @strSql = @strSql + ' SELECT DisplayOrder FROM '+@TableName+' WHERE '+@FieldName+'='+@ID + ' and Level='+@Level
END
ELSE
BEGIN
SET @strSql = @strSql + ' SELECT DisplayOrder FROM '+@TableName+' WHERE '+@FieldName+'='+@ID
END
INSERT INTO #TempDisplayOrder(DisplayOrder)
EXEC(@strSql)
SELECT @oDisplayOrder=DisplayOrder FROM #TempDisplayOrder
--PRINT @oDisplayOrder
IF(@Level <> '')
BEGIN
SET @strSqlNew =@strSqlNew+' Update '+ @TableName +' Set DisplayOrder='+@CurrentDisplayOrder+' WHERE '+@FieldName+'='+@ID
IF(@CurrentDisplayOrder > @oDisplayOrder)
BEGIN
SET @oDisplayOrder = @oDisplayOrder + 1
SET @strSqlNew1 =@strSqlNew1+' Update '+ @TableName +' Set DisplayOrder=DisplayOrder - 1 WHERE Level='+@Level+' and DisplayOrder Between '+@oDisplayOrder +' and '+@CurrentDisplayOrder +' and '+ @FieldName+'<>'+@ID
END
ELSE
BEGIN
SET @oDisplayOrder = @oDisplayOrder - 1
SET @strSqlNew1 =@strSqlNew1+' Update '+ @TableName +' Set DisplayOrder=DisplayOrder + 1 WHERE Level='+@Level+' and DisplayOrder Between '+@CurrentDisplayOrder +' and '+@oDisplayOrder +' and '+ @FieldName+'<>'+@ID
END
END
ELSE
BEGIN
SET @strSqlNew =@strSqlNew+' Update '+ @TableName +' Set DisplayOrder='+@CurrentDisplayOrder+' WHERE '+@FieldName+'='+@ID
IF(@CurrentDisplayOrder > @oDisplayOrder)
BEGIN
SET @oDisplayOrder = @oDisplayOrder + 1
SET @strSqlNew1 =@strSqlNew1+' Update '+ @TableName +' Set DisplayOrder=DisplayOrder - 1 WHERE DisplayOrder Between '+@oDisplayOrder +' and '+@CurrentDisplayOrder +' and '+ @FieldName+'<>'+@ID
END
ELSE
BEGIN
SET @oDisplayOrder = @oDisplayOrder - 1
SET @strSqlNew1 =@strSqlNew1+' Update '+ @TableName +' Set DisplayOrder=DisplayOrder + 1 WHERE DisplayOrder Between '+@CurrentDisplayOrder +' and '+@oDisplayOrder +' and '+ @FieldName+'<>'+@ID
END
END
--COMMIT TRAN
--RETURN @RetVal
--PRINT @CurrentDisplayOrder
--PRINT @strSqlNew
--PRINT @strSqlNew1
EXEC(@strSqlNew)
EXEC(@strSqlNew1)
END TRY
BEGIN CATCH
--ROLLBACK TRAN
--SET @RetVal = -1
--RETURN @RetVal
END CATCH
set QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Project : VirSanghvi
-- Procedure Name : [usp_Admin_DisplayOrder_ChangeDisplayOrder]
-- Author: Rajat
-- Create date: 17-Sep 2008
-- Description: updating the Forum Post
-- Modified By :
-- Modification Date:
-- =============================================
--usp_Admin_DisplayOrder_ChangeDisplayOrder 'Tbl_Article','ArticleID',1,3,''
-- select * from Tbl_ForumPost
ALTER PROCEDURE [dbo].[usp_Admin_DisplayOrder_ChangeDisplayOrder]
@TableName varchar(100),
@FieldName varchar(100),
@ID varchar(10),
@CurrentDisplayOrder varchar(10),
@Level varchar(100)
AS
DECLARE @RetVal INT,@strSql varchar(5000),@strSqlNew varchar(5000),@strSqlNew1 varchar(5000),@oDisplayOrder varchar(50)
SET @RetVal = -1
SET @strSql =''
SET @strSqlNew=''
SET @strSqlNew1=''
BEGIN TRY
--BEGIN TRAN
CREATE TABLE #TempDisplayOrder (
DisplayOrder varchar(50) )
IF(@Level <> '')
BEGIN
SET @strSql = @strSql + ' SELECT DisplayOrder FROM '+@TableName+' WHERE '+@FieldName+'='+@ID + ' and Level='+@Level
END
ELSE
BEGIN
SET @strSql = @strSql + ' SELECT DisplayOrder FROM '+@TableName+' WHERE '+@FieldName+'='+@ID
END
INSERT INTO #TempDisplayOrder(DisplayOrder)
EXEC(@strSql)
SELECT @oDisplayOrder=DisplayOrder FROM #TempDisplayOrder
--PRINT @oDisplayOrder
IF(@Level <> '')
BEGIN
SET @strSqlNew =@strSqlNew+' Update '+ @TableName +' Set DisplayOrder='+@CurrentDisplayOrder+' WHERE '+@FieldName+'='+@ID
IF(@CurrentDisplayOrder > @oDisplayOrder)
BEGIN
SET @oDisplayOrder = @oDisplayOrder + 1
SET @strSqlNew1 =@strSqlNew1+' Update '+ @TableName +' Set DisplayOrder=DisplayOrder - 1 WHERE Level='+@Level+' and DisplayOrder Between '+@oDisplayOrder +' and '+@CurrentDisplayOrder +' and '+ @FieldName+'<>'+@ID
END
ELSE
BEGIN
SET @oDisplayOrder = @oDisplayOrder - 1
SET @strSqlNew1 =@strSqlNew1+' Update '+ @TableName +' Set DisplayOrder=DisplayOrder + 1 WHERE Level='+@Level+' and DisplayOrder Between '+@CurrentDisplayOrder +' and '+@oDisplayOrder +' and '+ @FieldName+'<>'+@ID
END
END
ELSE
BEGIN
SET @strSqlNew =@strSqlNew+' Update '+ @TableName +' Set DisplayOrder='+@CurrentDisplayOrder+' WHERE '+@FieldName+'='+@ID
IF(@CurrentDisplayOrder > @oDisplayOrder)
BEGIN
SET @oDisplayOrder = @oDisplayOrder + 1
SET @strSqlNew1 =@strSqlNew1+' Update '+ @TableName +' Set DisplayOrder=DisplayOrder - 1 WHERE DisplayOrder Between '+@oDisplayOrder +' and '+@CurrentDisplayOrder +' and '+ @FieldName+'<>'+@ID
END
ELSE
BEGIN
SET @oDisplayOrder = @oDisplayOrder - 1
SET @strSqlNew1 =@strSqlNew1+' Update '+ @TableName +' Set DisplayOrder=DisplayOrder + 1 WHERE DisplayOrder Between '+@CurrentDisplayOrder +' and '+@oDisplayOrder +' and '+ @FieldName+'<>'+@ID
END
END
--COMMIT TRAN
--RETURN @RetVal
--PRINT @CurrentDisplayOrder
--PRINT @strSqlNew
--PRINT @strSqlNew1
EXEC(@strSqlNew)
EXEC(@strSqlNew1)
END TRY
BEGIN CATCH
--ROLLBACK TRAN
--SET @RetVal = -1
--RETURN @RetVal
END CATCH
Create CrumbTrail in SQLServer
CREATE TABLE [dbo].[Tbl_Category](
[CategoryID] [bigint] IDENTITY(1,1) NOT NULL,
[ParentCategoryID] [bigint] NULL,
[DisplayOrder] [int] NOT NULL,
[Level] [int] NULL,
[CategoryName] [varchar](100) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[Description] [varchar](500) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[IsPublish] [bit] NULL,
[IsDeleted] [int] NULL,
[CreationDate] [datetime] NULL,
[ModificationDate] [datetime] NULL,
[CreatedBy] [varchar](100) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[ModifiedBy] [varchar](100) COLLATE SQL_Latin1_General_CP1_CI_AS NULL
) ON [PRIMARY]
CREATE TABLE [dbo].[Tbl_ForumTopic](
[TopicID] [bigint] IDENTITY(1,1) NOT NULL,
[Title] [varchar](100) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[Description] [varchar](500) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[DisplayOrder] [int] NULL,
[IsDefault] [bit] NULL,
[IsPublish] [bit] NULL,
[IsDeleted] [int] NULL,
[CreatedBy] [varchar](100) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[ModifiedBy] [varchar](100) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[CreationDate] [datetime] NULL,
[ModificationDate] [datetime] NULL
) ON [PRIMARY]
CREATE TABLE [dbo].[Tbl_ForumPost](
[PostID] [bigint] IDENTITY(1,1) NOT NULL,
[FK_TopicID] [bigint] NULL,
[ParentPostID] [bigint] NULL,
[PostTitle] [varchar](1000) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[PostDescription] [text] COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[IsPublish] [bit] NULL,
[IsDeleted] [bit] NULL,
[CreatedBy] [varchar](100) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[ModifiedBy] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[UserType] [varchar](5) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[UserName] [varchar](100) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[EmailID] [varchar](100) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[UserImage] [varchar](100) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[CreationDate] [datetime] NULL,
[ModificationDate] [datetime] NULL
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
--- Procedure
ALTER Proc [dbo].[usp_Admin_Forum_CrumbTrail]
@PostID int
AS
BEGIN
CREATE TABLE #TempPost (
POSTID BIGINT IDENTITY(1,1) NOT NULL,
PostString varchar(8000))
CREATE TABLE #TempPostNew (
POSTID BIGINT ,
PostString varchar(8000))
Declare @HomePageLink varchar(100),@HomePage varchar(100),@QuestionPage varchar(100),@TopicPage varchar(100) ,@PostPage varchar(100)
Declare @strForumCrumbTail varchar(8000)
Declare @strForumCrumbTailPost varchar(8000)
Declare @strPostString varchar(8000)
Declare @CategoryID varchar(10),@TopicID varchar(10),@ParentPostID varchar(100),@TempPostID varchar(10)
Declare @CategoryName varchar(20),@TopicName varchar(20),@PostName varchar(20)
SET @strForumCrumbTailPost = ''
SET @strForumCrumbTail = ''
set @CategoryID=''
set @TopicID=''
set @QuestionPage='ForumListQuestion.aspx'
set @TopicPage ='ForumTopicList.aspx'
set @PostPage ='ForumListAllPostByPostID.aspx'
set @HomePage ='ForumCategoryList.aspx'
set @HomePageLink = 'Home'
--@CategoryID=FK_CategoryID,
select @TopicID=FK_TopicID,@ParentPostID=ParentPostID
from tbl_ForumPost where PostID=@PostID
/*
if(@CategoryID = '')
BEGIN
select @CategoryID=FK_CategoryID,@TopicID=TopicID
from tbl_ForumTopic where TopicID=@PostID
set @ParentPostID =''
END
if(@CategoryID !='')
BEGIN
select @CategoryName=CategoryName from tbl_ForumCategory where CategoryID=@CategoryID
set @strForumCrumbTail = ''+@CategoryName + ''
END
*/
if(@TopicID !='')
BEGIN
select @TopicName=Title from tbl_ForumTopic where TopicID=@TopicID
set @strForumCrumbTail = ''+@TopicName + ''
END
if(@PostID !='')
BEGIN
if(@ParentPostID > 0)
BEGIN
While(@ParentPostID > 0)
Begin
select @TempPostID = PostID,@ParentPostID = ParentPostID,@PostName=PostTitle from tbl_ForumPost where PostID= @ParentPostID
set @strPostString = ''+@PostName + '' + ' >> '
INSERT INTO #TempPost(PostString)values(@strPostString)
End
END
END
INSERT INTO #TempPostNew(POSTID,PostString)
select POSTID,PostString from #TempPost ORDER BY 1 desc
SELECT @strForumCrumbTailPost = @strForumCrumbTailPost + PostString FROM #TempPostNew
if(@strForumCrumbTailPost <>'')
BEGIN
set @strForumCrumbTail = @HomePageLink+' >> '+ @strForumCrumbTail + ' >> '+ @strForumCrumbTailPost
SELECT substring(@strForumCrumbTail,0,len(@strForumCrumbTail)-2)
END
ELSE
BEGIN
set @strForumCrumbTail = @HomePageLink+' >> '+ @strForumCrumbTail
SELECT @strForumCrumbTail
END
END
[CategoryID] [bigint] IDENTITY(1,1) NOT NULL,
[ParentCategoryID] [bigint] NULL,
[DisplayOrder] [int] NOT NULL,
[Level] [int] NULL,
[CategoryName] [varchar](100) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[Description] [varchar](500) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[IsPublish] [bit] NULL,
[IsDeleted] [int] NULL,
[CreationDate] [datetime] NULL,
[ModificationDate] [datetime] NULL,
[CreatedBy] [varchar](100) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[ModifiedBy] [varchar](100) COLLATE SQL_Latin1_General_CP1_CI_AS NULL
) ON [PRIMARY]
CREATE TABLE [dbo].[Tbl_ForumTopic](
[TopicID] [bigint] IDENTITY(1,1) NOT NULL,
[Title] [varchar](100) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[Description] [varchar](500) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[DisplayOrder] [int] NULL,
[IsDefault] [bit] NULL,
[IsPublish] [bit] NULL,
[IsDeleted] [int] NULL,
[CreatedBy] [varchar](100) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[ModifiedBy] [varchar](100) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[CreationDate] [datetime] NULL,
[ModificationDate] [datetime] NULL
) ON [PRIMARY]
CREATE TABLE [dbo].[Tbl_ForumPost](
[PostID] [bigint] IDENTITY(1,1) NOT NULL,
[FK_TopicID] [bigint] NULL,
[ParentPostID] [bigint] NULL,
[PostTitle] [varchar](1000) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[PostDescription] [text] COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[IsPublish] [bit] NULL,
[IsDeleted] [bit] NULL,
[CreatedBy] [varchar](100) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[ModifiedBy] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[UserType] [varchar](5) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[UserName] [varchar](100) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[EmailID] [varchar](100) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[UserImage] [varchar](100) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[CreationDate] [datetime] NULL,
[ModificationDate] [datetime] NULL
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
--- Procedure
ALTER Proc [dbo].[usp_Admin_Forum_CrumbTrail]
@PostID int
AS
BEGIN
CREATE TABLE #TempPost (
POSTID BIGINT IDENTITY(1,1) NOT NULL,
PostString varchar(8000))
CREATE TABLE #TempPostNew (
POSTID BIGINT ,
PostString varchar(8000))
Declare @HomePageLink varchar(100),@HomePage varchar(100),@QuestionPage varchar(100),@TopicPage varchar(100) ,@PostPage varchar(100)
Declare @strForumCrumbTail varchar(8000)
Declare @strForumCrumbTailPost varchar(8000)
Declare @strPostString varchar(8000)
Declare @CategoryID varchar(10),@TopicID varchar(10),@ParentPostID varchar(100),@TempPostID varchar(10)
Declare @CategoryName varchar(20),@TopicName varchar(20),@PostName varchar(20)
SET @strForumCrumbTailPost = ''
SET @strForumCrumbTail = ''
set @CategoryID=''
set @TopicID=''
set @QuestionPage='ForumListQuestion.aspx'
set @TopicPage ='ForumTopicList.aspx'
set @PostPage ='ForumListAllPostByPostID.aspx'
set @HomePage ='ForumCategoryList.aspx'
set @HomePageLink = 'Home'
--@CategoryID=FK_CategoryID,
select @TopicID=FK_TopicID,@ParentPostID=ParentPostID
from tbl_ForumPost where PostID=@PostID
/*
if(@CategoryID = '')
BEGIN
select @CategoryID=FK_CategoryID,@TopicID=TopicID
from tbl_ForumTopic where TopicID=@PostID
set @ParentPostID =''
END
if(@CategoryID !='')
BEGIN
select @CategoryName=CategoryName from tbl_ForumCategory where CategoryID=@CategoryID
set @strForumCrumbTail = ''+@CategoryName + ''
END
*/
if(@TopicID !='')
BEGIN
select @TopicName=Title from tbl_ForumTopic where TopicID=@TopicID
set @strForumCrumbTail = ''+@TopicName + ''
END
if(@PostID !='')
BEGIN
if(@ParentPostID > 0)
BEGIN
While(@ParentPostID > 0)
Begin
select @TempPostID = PostID,@ParentPostID = ParentPostID,@PostName=PostTitle from tbl_ForumPost where PostID= @ParentPostID
set @strPostString = ''+@PostName + '' + ' >> '
INSERT INTO #TempPost(PostString)values(@strPostString)
End
END
END
INSERT INTO #TempPostNew(POSTID,PostString)
select POSTID,PostString from #TempPost ORDER BY 1 desc
SELECT @strForumCrumbTailPost = @strForumCrumbTailPost + PostString FROM #TempPostNew
if(@strForumCrumbTailPost <>'')
BEGIN
set @strForumCrumbTail = @HomePageLink+' >> '+ @strForumCrumbTail + ' >> '+ @strForumCrumbTailPost
SELECT substring(@strForumCrumbTail,0,len(@strForumCrumbTail)-2)
END
ELSE
BEGIN
set @strForumCrumbTail = @HomePageLink+' >> '+ @strForumCrumbTail
SELECT @strForumCrumbTail
END
END
To pass a table name and FieldName as Parameter in SQl procedure(Update Display Order)
--usp_Admin_DisplayOrder_UpdateDisplayOrder 'Tbl_Category','1'
-- select * from Tbl_ForumPost
ALTER PROCEDURE [dbo].[usp_Admin_DisplayOrder_UpdateDisplayOrder]
@TableName varchar(100),
@Level varchar(10)
AS
DECLARE @RetVal INT,@strSql varchar(1000)
SET @RetVal = -1
SET @strSql =''
BEGIN TRY
BEGIN TRAN
IF(@Level <> '')
BEGIN
SET @strSql =@strSql+' Update '+ @TableName +' Set DisplayOrder=IsNull(DisplayOrder,0) +1 WHERE Level='+@Level
END
ELSE
BEGIN
SET @strSql =@strSql+' Update '+ @TableName +' Set DisplayOrder=IsNull(DisplayOrder,0) +1'
END
EXEC(@strSql)
COMMIT TRAN
--RETURN @RetVal
--PRINT @strSql
END TRY
BEGIN CATCH
ROLLBACK TRAN
SET @RetVal = -1
RETURN @RetVal
END CATCH
-- select * from Tbl_ForumPost
ALTER PROCEDURE [dbo].[usp_Admin_DisplayOrder_UpdateDisplayOrder]
@TableName varchar(100),
@Level varchar(10)
AS
DECLARE @RetVal INT,@strSql varchar(1000)
SET @RetVal = -1
SET @strSql =''
BEGIN TRY
BEGIN TRAN
IF(@Level <> '')
BEGIN
SET @strSql =@strSql+' Update '+ @TableName +' Set DisplayOrder=IsNull(DisplayOrder,0) +1 WHERE Level='+@Level
END
ELSE
BEGIN
SET @strSql =@strSql+' Update '+ @TableName +' Set DisplayOrder=IsNull(DisplayOrder,0) +1'
END
EXEC(@strSql)
COMMIT TRAN
--RETURN @RetVal
--PRINT @strSql
END TRY
BEGIN CATCH
ROLLBACK TRAN
SET @RetVal = -1
RETURN @RetVal
END CATCH
Thursday, September 11, 2008
Custom Paging
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
GO
--usp_GetEmpList 2,2,0
ALTER PROC [dbo].[usp_GetEmpList]
@startRowIndex int,
@maximumRows int,
@totalRows int OUTPUT
AS
DECLARE @first_id int, @startRow int
SET @startRowIndex = (@startRowIndex - 1) * @maximumRows
IF @startRowIndex = 0
SET @startRowIndex = 1
SET ROWCOUNT @startRowIndex
SELECT @first_id = CategoryId FROM Tbl_Category ORDER BY CategoryId
IF @startRowIndex = 1
set @first_id = @first_id
else
set @first_id = @first_id + 1
PRINT @first_id
SET ROWCOUNT @maximumRows
SELECT * FROM Tbl_Category WHERE CategoryId >= @first_id ORDER BY CategoryId
SET ROWCOUNT 0
-- GEt the total rows
SELECT @totalRows = COUNT(CategoryId) FROM Tbl_Category
set QUOTED_IDENTIFIER ON
GO
--usp_GetEmpList 2,2,0
ALTER PROC [dbo].[usp_GetEmpList]
@startRowIndex int,
@maximumRows int,
@totalRows int OUTPUT
AS
DECLARE @first_id int, @startRow int
SET @startRowIndex = (@startRowIndex - 1) * @maximumRows
IF @startRowIndex = 0
SET @startRowIndex = 1
SET ROWCOUNT @startRowIndex
SELECT @first_id = CategoryId FROM Tbl_Category ORDER BY CategoryId
IF @startRowIndex = 1
set @first_id = @first_id
else
set @first_id = @first_id + 1
PRINT @first_id
SET ROWCOUNT @maximumRows
SELECT * FROM Tbl_Category WHERE CategoryId >= @first_id ORDER BY CategoryId
SET ROWCOUNT 0
-- GEt the total rows
SELECT @totalRows = COUNT(CategoryId) FROM Tbl_Category
Tuesday, September 9, 2008
Wednesday, September 3, 2008
n-TIER Code
http://www.microsoft.com/belux/msdn/nl/community/columns/hyatt/ntier3.mspx
http://www.microsoft.com/belux/msdn/nl/community/columns/hyatt/ntier2.mspx
http://www.microsoft.com/belux/msdn/nl/community/columns/hyatt/ntier1.mspx
http://www.microsoft.com/belux/msdn/nl/community/columns/hyatt/ntier2.mspx
http://www.microsoft.com/belux/msdn/nl/community/columns/hyatt/ntier1.mspx
Tuesday, September 2, 2008
Generices
http://msdn.microsoft.com/en-us/library/512aeb7t(VS.80).aspx
http://www.c-sharpcorner.com/UploadFile/sdhar8po/GenericsInCSharp11152005055344AM/GenericsInCSharp.aspx
http://www.csharp-station.com/Tutorials/Lesson20.aspx
http://www.codeproject.com/Articles/8360/Generics-in-C-2-0
http://www.c-sharpcorner.com/UploadFile/sdhar8po/GenericsInCSharp11152005055344AM/GenericsInCSharp.aspx
http://www.csharp-station.com/Tutorials/Lesson20.aspx
http://www.codeproject.com/Articles/8360/Generics-in-C-2-0
Monday, September 1, 2008
Arraylist collection List
aspx Page
asp:GridView ID="Gv_User" runat="server" AutoGenerateColumns="false"
onrowdatabound="Gv_User_RowDataBound"
asp:BoundField DataField="UserID" HeaderText="User ID" />
asp:BoundField DataField="UserName" HeaderText="User Name" />
asp:TemplateField>
ItemTemplate>
asp:Label ID="lblUserID" runat="server" >
/ItemTemplate>
/asp:TemplateField>
/Columns>
/asp:GridView
CS File
public partial class CollectionClass : System.Web.UI.Page
{
ArrayList arr = new ArrayList();
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
ArrayList arrnew= getData();
Gv_User.DataSource = arrnew;
Gv_User.DataBind();
//foreach (User A1 in arrnew)
//{
// Response.Write(A1.UserName);
// Response.Write(A1.UserID);
//}
}
}
private ArrayList getData()
{
string sSQL = "select cast(ID as int),Name from tbl_test";
string sConnString = ConfigurationManager.ConnectionStrings["octanmen"].ToString();
using (SqlConnection oCn = new SqlConnection(sConnString))
{
SqlCommand oSelCmd = new SqlCommand(sSQL, oCn);
oSelCmd.CommandType = CommandType.Text;
oCn.Open();
SqlDataReader oDr = oSelCmd.ExecuteReader();
while (oDr.Read())
{
User objUser = new User();
objUser.UserID = oDr.GetInt32(0);
objUser.UserName = oDr.GetString(1);
arr.Add(objUser);
}
oDr.Close();
oCn.Close();
// return the finished ArrayList with customer objects
return arr;
}
}
//private void Printdata(IEnumerable myList)
//{
// IEnumerator myEnumerator = myList.GetEnumerator();
// while (myEnumerator.MoveNext())
// Response.Write(myEnumerator.Current);
//}
protected void Gv_User_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
Label lblUserID = (Label)e.Row.FindControl("lblUserID");
lblUserID.Text = DataBinder.Eval(e.Row.DataItem, "UserID").ToString();
}
}
}
public class User
{
private int m_intUserID = 0;
private string m_strName;
public int UserID { get { return m_intUserID; } set { m_intUserID = value; } }
public string UserName { get { return m_strName; } set { m_strName = value; } }
}
asp:GridView ID="Gv_User" runat="server" AutoGenerateColumns="false"
onrowdatabound="Gv_User_RowDataBound"
asp:BoundField DataField="UserName" HeaderText="User Name" />
asp:TemplateField>
ItemTemplate>
asp:Label ID="lblUserID" runat="server" >
/ItemTemplate>
/asp:TemplateField>
/Columns>
/asp:GridView
CS File
public partial class CollectionClass : System.Web.UI.Page
{
ArrayList arr = new ArrayList();
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
ArrayList arrnew= getData();
Gv_User.DataSource = arrnew;
Gv_User.DataBind();
//foreach (User A1 in arrnew)
//{
// Response.Write(A1.UserName);
// Response.Write(A1.UserID);
//}
}
}
private ArrayList getData()
{
string sSQL = "select cast(ID as int),Name from tbl_test";
string sConnString = ConfigurationManager.ConnectionStrings["octanmen"].ToString();
using (SqlConnection oCn = new SqlConnection(sConnString))
{
SqlCommand oSelCmd = new SqlCommand(sSQL, oCn);
oSelCmd.CommandType = CommandType.Text;
oCn.Open();
SqlDataReader oDr = oSelCmd.ExecuteReader();
while (oDr.Read())
{
User objUser = new User();
objUser.UserID = oDr.GetInt32(0);
objUser.UserName = oDr.GetString(1);
arr.Add(objUser);
}
oDr.Close();
oCn.Close();
// return the finished ArrayList with customer objects
return arr;
}
}
//private void Printdata(IEnumerable myList)
//{
// IEnumerator myEnumerator = myList.GetEnumerator();
// while (myEnumerator.MoveNext())
// Response.Write(myEnumerator.Current);
//}
protected void Gv_User_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
Label lblUserID = (Label)e.Row.FindControl("lblUserID");
lblUserID.Text = DataBinder.Eval(e.Row.DataItem, "UserID").ToString();
}
}
}
public class User
{
private int m_intUserID = 0;
private string m_strName;
public int UserID { get { return m_intUserID; } set { m_intUserID = value; } }
public string UserName { get { return m_strName; } set { m_strName = value; } }
}
Subscribe to:
Posts (Atom)