minimize the number of postbacks - asp.net

i have senerio like that
i have three table
department
[Dep_No_ID] [int] IDENTITY(1,1) NOT NULL,
[Dep_Name] [nvarchar](100) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[Dep_Code] [nvarchar](100) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
test
[Test_ID] [int] IDENTITY(1,1) NOT NULL,
[Test_Code] [nvarchar](100) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
[Test_Name] [nvarchar](100) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
[Tests_DepartMent_Code] [nvarchar](100) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[Tests_Group_Code] [nvarchar](100) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[Tests_Rate] [decimal](18, 2) NULL,
and
sub_test
[Sub_Test_ID] [int] IDENTITY(1,1) NOT NULL,
[Sub_Test_Code] [nvarchar](100) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[Sub_Test_Name] [nvarchar](100) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[Sub_Tests_Test_Code] [nvarchar](100) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[Sub_Tests_DepartMent_Code] [nvarchar](100) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[Sub_Tests_Group_Code] [nvarchar](100) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[Sub_Test_Rate] [decimal](18, 2) NULL,
In my aspx page I show the Departments in a DropDownList when the user select the Department a request is going to server side and the Grid is bind with the Tests. And in this Gridview i have a Checkboxes in all rows when user check this check box a request is again going to the Server Side and second Gridview is bind with Subtests according to Tests,in all that ,Postback is occur is many times which decrease my efficiency because user select multiple test and Subtest from multiple department. Can any one give me idea,how i simlify this senerio by which minimum number of Postback occur
(in test and subtest grid i have 5-5 columns)

If you need quality and a well performing result, as well as if you can spend a little more time, jQuery with a good grid plug-in is the best option.
here's a good option.
jqGrid demos
UpdatePannel is a pretty bad option, which should be only considered when you have a limited time, not much concerned in performance, and when the page with less content.

You can make Jquery AJAX calls to get the conditional data or can use AJAX Update Panel instead.

Related

FullCalendar events table connot have foreign key?

I'm using fullCalendar jQuery plugin in which users can add events to a database table..
This is my events table
CREATE TABLE [dbo].[Events]
(
[EventID] [int] IDENTITY(1,1) NOT NULL,
[Subject] [nvarchar](100) NULL,
[Description] [nvarchar](300) NULL,
[Start] [datetime] NOT NULL,
[EndT] [datetime] NULL,
[ThemeColor] [nvarchar](10) NULL,
[IsFullDay] [bit] NULL,
[userID] [int] NOT NULL,
PRIMARY KEY [EventID]
)
ALTER TABLE [dbo].[Events] WITH CHECK
ADD CONSTRAINT [FK_Events_Users]
FOREIGN KEY([userID]) REFERENCES [dbo].[Users] ([userID])
It works well and the getEvents function successes .. But, When I tried to associate the events table with another table in the database (add a foreign key that reference another table like the users table)
[userID] [int] NOT NULL,
the fullCalendar fails to load .. I can not even see the calendar on the page
If I remove the relationship it works..
How can I make it work without removing the relationship as I need to know the events belongs to which user..??
Thanks
I'm using SQL Server ..

Display data at Default.aspx after secure Login Using label, text box in asp.net

I want to display Data after Secure Login. Using Label and textboxes. And also want to use session variable to expire login.
My problem is that. how to display this data in user Home page.
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[tblEmployeeDetail](
[EmployeeID] [int] IDENTITY(1,1) NOT NULL,
[FirstName] [nvarchar](25) NOT NULL,
[LastName] [nvarchar](25) NOT NULL,
[UserName] [nvarchar](50) NOT NULL,
[Gender] [nvarchar](20) NOT NULL,
[Password] [nvarchar](50) NOT NULL,
[Email] [nvarchar](50) NOT NULL,
[Telephone] [bigint] NOT NULL,
[HouseNo] [nvarchar](25) NOT NULL,
[Street] [nvarchar](25) NOT NULL,
[Locality] [nvarchar](25) NOT NULL,
[City] [nvarchar](50) NOT NULL,
[State] [nvarchar](50) NOT NULL,
[Pincode] [int] NOT NULL,
[Country] [nvarchar](50) NOT NULL,
CONSTRAINT [PK_tblEmployeeDetail] PRIMARY KEY CLUSTERED
(
[EmployeeID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
Facebook basically shows the data of your friends, the pages u liked, or the links u posted, commented or liked. That means each data what is are getting in your page is somehow related with you. It is basically the relationship between all these tables where the data is managed. Use join on the bases of userId and user friends userIds, you will get all the data you require.

SQL Server identity column skipping ids on insert - no errors detected in logs

I am using SQL Server 2008 to maintain a database where I have an userAcccounts table where the user details are stored while registering on the website. The userID column is an integer with identity on.
What I have noticed is that somehow, the column is skipping some ids (random number of ids, sometimes it skips 5,11,10 etc), i.e., the ID's are not consecutive. I have a read a similar question here, with a similar issue which suggested
"An identity sequence is incremented any time an insert is attempted
-- this includes a failed or rolled back INSERT"
I have checked my logs for errors, but there were no error during the period when the ids were skipped. Also my insert is not within any transaction for a rollback to happen, because there is no requirement of deleting an account. Also no other tables are involved during the registration
Although this is not a major issue as the ids will be unique nevertheless, what I would like to find out is why this behavior?
Perhaps I am overlooking something.
Are there any other scenarios where this kind of behavior can occur? i.e. the identity column skipping a few ids? Could this be an issue with concurrent access?
here is the table's create script.
CREATE TABLE [dbo].[UserAccounts](
[AccountID] [int] IDENTITY(1,1) NOT NULL,
[FirstName] [varchar](30) NULL,
[LastName] [varchar](30) NULL,
[Gender] [varchar](10) NULL,
[Email] [varchar](150) NULL,
[EmailVerified] [bit] NULL,
[UserName] [varchar](30) NULL,
[Password] [varchar](50) NULL,
[ProfilePicture] [varchar](150) NULL,
[BackgroundPicture] [varchar](150) NULL,
[DateOfBirth] [smalldatetime] NULL,
[CreateDate] [smalldatetime] NULL,
[LastUpdatedOn] [smalldatetime] NULL,
[Points] [int] NULL,
[CurrentBadge] [varchar](30) NULL,
[FBID] [varchar](50) NULL,
[TwitterID] [varchar](50) NULL,
[Abused] [int] NULL,
[isActive] [bit] NULL,
[AccountTypeID] [int] NULL,
[DateStamp] [timestamp] NOT NULL,
[Location] [varchar](50) NULL,
[About] [varchar](250) NULL,
[UsingBackgroundPicture] [bit] NULL,
CONSTRAINT [PK__UserAcco__349DA5867F60ED59] PRIMARY KEY CLUSTERED
(
[AccountID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
Any help in this regard is appreciated? Also if you require any other detail, please let me know.
Thanks
It's impossible to guarantee exact sequentiality of Sequences or IDs, without globally locking the entire database on every transaction -- to prevent any concurrent transactions, which could possibly also ask for an ID.
This would obviously reduce it to effectively a single-user database, and totally destroy performance.
For such reasons, there is explicitly no guarantee of continuous sequentiality.

Sql Query to Drill down to a table to minimum level as per RoleID and Hierarchy Structure

We have a application where users are entering their time efforts .We have two tables, Production table for entering all production tasks and NonProduction for entering all non production related tasks in the application.We also have a UserInfo table where all the user information is stored like his eCode, Name, Designation,RoleID,ImmediateSupervisor ECode to whom the user is reporting etc.
We are trying to make a sql query in such manner so that any users whose roleid is greater then 1 can drill down and extract the Production and NonProduction information of the users reporting under him but the condition is that the extracted report is of RoleID 1 only.
For example, A Manager RoleID is 4 ,so firstly he drill down and find all the users reporting to him (This info is in ImmediateSupervisor column on UserInfo table)i.e RoleID 3 or RoleID 4, then again we drill down to these Users and extract information who are reporting to them and continue until we drill down up to ROleID 1 and once we drill down to that level, we extract respective users Production and NonProduction details and display in the Report.
Below is the table structure query in Create Table format;
Production Table
CREATE TABLE [dbo].[Production]
(
[ProductionTimeEntryID] [int] IDENTITY(100, 1) NOT NULL,
[CalendarDate] [datetime] NOT NULL,
[UserID] [int] NOT NULL,
[NatureOfWorkID] [int] NOT NULL,
[RegionProjectID] [int] NOT NULL,
[CountyID] [int] NOT NULL,
[WorkTypeID] [int] NOT NULL,
[TaskID] [int] NOT NULL,
[VolumeProcessed] [int] NOT NULL,
[NosOfError] [int] NULL,
[NosOfVolumeAudited] [int] NULL,
[TimeSpent] [varchar](25) NULL,
[Comment] [varchar](250) NULL,
[IsTaskCompleted] [int] NOT NULL,
[isCurrentDayTask] [bit] NOT NULL,
[SupervisorECode] [nvarchar](50) NULL,
CONSTRAINT [PK_Production] PRIMARY KEY CLUSTERED([ProductionTimeEntryID] ASC)
WITH (
PAD_INDEX = OFF,
STATISTICS_NORECOMPUTE = OFF,
IGNORE_DUP_KEY = OFF,
ALLOW_ROW_LOCKS = ON,
ALLOW_PAGE_LOCKS = ON
) ON [PRIMARY]
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
ALTER TABLE [dbo].[Production] WITH NOCHECK ADD CONSTRAINT
[FK_Production_County] FOREIGN KEY([CountyID])
REFERENCES [dbo].[County] ([CountyID])
GO
ALTER TABLE [dbo].[Production] CHECK CONSTRAINT [FK_Production_County]
GO
ALTER TABLE [dbo].[Production] WITH NOCHECK ADD CONSTRAINT
[FK_Production_NatureOfWork] FOREIGN KEY([NatureOfWorkID])
REFERENCES [dbo].[NatureOfWork] ([NatureOfWorkID])
ON
UPDATE CASCADE
ON
DELETE CASCADE
GO
ALTER TABLE [dbo].[Production] CHECK CONSTRAINT [FK_Production_NatureOfWork]
GO
ALTER TABLE [dbo].[Production] WITH NOCHECK ADD CONSTRAINT
[FK_Production_RegionAndProjectInfo] FOREIGN KEY([RegionProjectID])
REFERENCES [dbo].[RegionAndProjectInfo] ([RegionProjectID])
GO
ALTER TABLE [dbo].[Production] CHECK CONSTRAINT
[FK_Production_RegionAndProjectInfo]
GO
ALTER TABLE [dbo].[Production] WITH CHECK ADD CONSTRAINT
[FK_Production_Task] FOREIGN KEY([TaskID])
REFERENCES [dbo].[Task] ([TaskID])
GO
ALTER TABLE [dbo].[Production] CHECK CONSTRAINT [FK_Production_Task]
GO
ALTER TABLE [dbo].[Production] WITH CHECK ADD CONSTRAINT
[FK_Production_USERINFO] FOREIGN KEY([UserID])
REFERENCES [dbo].[USERINFO] ([UserID])
ON
UPDATE CASCADE
ON
DELETE CASCADE
GO
ALTER TABLE [dbo].[Production] CHECK CONSTRAINT [FK_Production_USERINFO]
GO
ALTER TABLE [dbo].[Production] WITH CHECK ADD CONSTRAINT
[FK_Production_WorkType] FOREIGN KEY([WorkTypeID])
REFERENCES [dbo].[WorkType] ([WorkTypeID])
ON
UPDATE CASCADE
ON
DELETE CASCADE
GO
ALTER TABLE [dbo].[Production] CHECK CONSTRAINT [FK_Production_WorkType]
GO
ALTER TABLE [dbo].[Production] ADD DEFAULT((0)) FOR [IsTaskCompleted]
GO
ALTER TABLE [dbo].[Production] ADD DEFAULT((0)) FOR [isCurrentDayTask]
GO
UserInfo Table:
CREATE TABLE [dbo].[USERINFO](
[UserID] [int] IDENTITY(1,1) NOT NULL,
[UserECode] [nvarchar](50) NOT NULL,
[UserName] [nvarchar](250) NOT NULL,
[CCCode] [nvarchar](50) NULL,
[CCName] [nvarchar](50) NULL,
[Password] [varchar](50) NULL,
[IsFlagEnabled] [bit] NULL,
[IsFirstTimeUserLoggedIn] [bit] NULL,
[EmailAddress] [nvarchar](250) NULL,
[Designation] [varchar](50) NULL,
[ShiftStartTime] [varchar](8) NULL,
[ShiftEndTime] [varchar](8) NULL,
[WeekendShiftStartTime] [varchar](8) NULL,
[WeekendShiftEndTime] [varchar](8) NULL,
[RoleID] [int] NULL,
[ShiftEndFlagStatus] [int] NOT NULL,
[ShiftStartTimeWithTimeStamp] [datetime] NULL,
[ShiftEndTimeWithTimeStamp] [datetime] NULL,
[LoggedInDateTime] [datetime] NULL,
[FirstLoggedInOnthedayflag] [int] NOT NULL,
[ImmediateSupervisor] [nvarchar](50) NULL,
CONSTRAINT [PK_USER] PRIMARY KEY CLUSTERED
(
[UserID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
ALTER TABLE [dbo].[USERINFO] ADD DEFAULT ((1)) FOR [RoleID]
GO
ALTER TABLE [dbo].[USERINFO] ADD DEFAULT ((1)) FOR [ShiftEndFlagStatus]
GO
ALTER TABLE [dbo].[USERINFO] ADD DEFAULT ((1)) FOR [FirstLoggedInOnthedayflag]
GO
How to make such query or type of query to incorporate same in my application?
You have a table with a tree structure, the standard way to extract this is to use a recursive cte, something like this:
;with UserTree as
(
select UserECode, UserID
from USERINFO
where UserID = <the managers user-id>
union all
select UserECode, UserID
from UserTree parent
inner join USERINFO child
on child.ImmediateSupervisor = parent.UserECode
)
select * --change this to the specific columns that you need
from UserTree ut
inner join Production p
on p.UserID = ut.UserID
where RoleId = 1
Please note that I haven't managed to test this code, but I'm sure you can fix any minor issues yourself.
More information about recursive cte:s.
I also couldn't help but notice a couple of potential issues with your tree datastructure: ImmediateSupervisor appears to reference UserECode, and I can see two problems in the table structure that you have posted:
No foreign key from ImmediateSupervisor to UserECode. This could result in users that have non-existing supervisors.
UserECode is not unique. This could result in multiple users with the same code, which means multiple supervisors per user, and that will really screw up the recursive cte query.
I don't have the whole picture here, but with what I have I would change the ImmediateSupervisor-column to refer to the PK UserId instead.
with
ProductionCTE(CalendarDate,RoleID,UserID,UserECode,UserName,ImmediateSupervisor,NatureOfWorkName,RegionProjectName,CountyName,WorkTypeName,TaskName,VolumneProcessed,TimeSpent,Comment)
as
(
select P.CalendarDate,U.RoleID,U.UserID,U.UserECode,U.UserName,U.ImmediateSupervisor,N.NatureofWorkName,
R.RegionProjectName,C.Countyname,W.WorktypeName,T.TaskName,P.VolumeProcessed,P.Timespent,P.Comment
from production P inner join NatureOfWork N
on N.NatureofWorkID=P.natureofworkid
inner join dbo.RegionAndProjectInfo R
on R.RegionProjectID=P.RegionProjectID
inner join county C
on C.countyid=P.countyid
inner join worktype W
on W.Worktypeid=P.worktypeID
inner join task T
on T.taskid=P.TaskID
inner join UserInfo U
on U.Userid=P.userid
where P.userid=952
union all
select P.CalendarDate,U.RoleID,U.UserID,U.UserECode,U.UserName,U.ImmediateSupervisor,N.NatureofWorkName,
R.RegionProjectName,C.Countyname,W.WorktypeName,T.TaskName,P.VolumeProcessed,P.Timespent,P.Comment
from production P inner join NatureOfWork N
on N.NatureofWorkID=P.natureofworkid
inner join dbo.RegionAndProjectInfo R
on R.RegionProjectID=P.RegionProjectID
inner join county C
on C.countyid=P.countyid
inner join worktype W
on W.Worktypeid=P.worktypeID
inner join task T
on T.taskid=P.TaskID
inner join UserInfo U
on U.Userid=P.userid
inner join ProductionCTE
on U.ImmediateSupervisor=ProductionCTE.UserECode
)
select distinct CalendarDate,RoleID,UserID,UserECode,UserName,ImmediateSupervisor,NatureOfWorkName,RegionProjectName,CountyName,WorkTypeName,TaskName,VolumneProcessed,TimeSpent,Comment from ProductionCTE order by UserECode
Implementing Recursive CTE fixed the issue and now ia m able to extract the records as per hierarchy.

System.Data.SqlClient.SqlException: Timeout expired due to index?

After creating an index on a rather small table (approx. 700 rows, 10 colums) I started to get
System.Data.SqlClient.SqlException: Timeout expired
The index was clusterd on the primary key.
There are no triggers.
All of these errors occured when doing an update via a stored procedure.
After I removed the index I had no more time-out issues.
Setting CommandTimeout did not help.
Does anybody has an idea why this was happening?
stored procedure (nothing special here)
Update objects set date_last_datacollect=#date_last_datacollect,
date_last_error='',message_last_error='' where objectid = #objectid
Table structure
CREATE TABLE [dbo].[objects](
[id] [int] IDENTITY(1,1) NOT NULL,
[objectid] [nvarchar](50) NULL,
[name] [nvarchar](max) NULL,
[adminid] [nvarchar](50) NULL,
[token] [nvarchar](max) NULL,
[type] [nvarchar](max) NULL,
[date_added] [date] NULL,
[date_last_update] [datetime] NULL,
[date_last_datacollect] [datetime] NULL,
[date_last_error] [datetime] NULL,
[message_last_error] [nvarchar](max) NULL,
[active] [bit] NULL,
[logourl] [nchar](255) NULL
) ON [PRIMARY]
edit:
After viewing my table structure I realize it might be due to the missing primary key?
Have you tried updating statistics on the table?

Resources