C# – GridView – Custom Paging in ASP .NET 2.0 with Microsoft SQL Server 2005 using ROW_NUMBER() and VirtualItemCount

Add a datagrid to your aspx page.
Set the following properties in the designer:


Add the pagerstyle to the datagrid
<PagerStyle PageButtonCount="10" Mode="NumericPages"></PagerStyle>

Add the following events

protected void dgZendingen_PageIndexChanged(object source, DataGridPageChangedEventArgs e)
            dgZendingen.CurrentPageIndex = e.NewPageIndex;

And Functions

        public void BindDataGrid()

            int startindex = 1;
            if (dg.CurrentPageIndex > 0)
                    startindex = (dg.PageSize * dg.CurrentPageIndex) + 1;
                startindex = 1;
            ds = // get subset of items with sp pSubSetItemsSelect;
            if (dg.CurrentPageIndex == 0)
                    dg.VirtualItemCount = // get total item count with sp pTotalCount;

            DataView dv = ds.Tables[0].DefaultView;
            dgZendingen.DataSource = dv;

Create 2 stored procedures, the first to calculate the total item count and the second to get the subset of items

First sp
if exists (select * from dbo.sysobjects where name = ‘pTotalCount’ and xtype = ‘p’)
    drop procedure pTotalCount

create    procedure pTotalCount

    declare @totalCount int
    set @totalCount = 0        
    select @totalCount = count(1)
        Table1 t (nolock)

Second Sp

if exists (select * from dbo.sysobjects where name = ‘pSubSetItemsSelect’ and xtype = ‘p’)
    drop procedure pSubSetItemsSelect

create    procedure pSubSetItemsSelect
    @MaxItemsOnPage int = 20,
    @StartIndex int = 0

    select DerivedTable.RowNum, DerivedTable.Id, DerivedTable.[Message]
                select row_number() over(order by [Message]) as RowNum, Table1.Id, Table1.[Message]
                    Table1 t (nolock)
            ) as DerivedTable
    where RowNum between @StartIndex and (@StartIndex + @MaxItemsOnPage) 1

Add a diagram to an Microsoft SQL Server 2005 database, Error: Database diagram support objects cannot be installed because this database does not have a valid owner etc.

When trying to add a diagram to an SQL Server 2005 db I got the following error:
Database diagram support objects cannot be installed because this database does not have a valid owner.
To continue, first use the Files page of the Database Properties dialog box or the ALTER AUTHORIZATION statement
to set the database owner to a valid login, then add the database diagram support objects.
In SQL Server Management Studio do the following:
Right Click on your database, choose properties
Goto the Options Page
In the Dropdown at right labeled "Compatibility Level" choose "SQL Server 2005(90)"


C# – Directory.CreateDirecotry and Logon failure: unknown user name or bad password.

When you want to create a folder on a network share on an other domain with the code Directory.CreateDirectory(@"\\nas\test")
, you can get a exception [Logon failure: unknown user name or bad password.]
Giving Full Control Permissions to the Everyone account does not solve the problem, because the application pool account is using a domain account [A] and the share
needs domain account [B] permissions

Create domain account [A] (eg. DOMAIN_A\User1 with password 12345A)
Create domain account [B] (eg. DOMAIN_B\User1 with password 12345A)
Make sure the application pool identity = DOMAIN_A\User1
Make sure the domain account DOMAIN_B\User1 has full control permissions on NetwerkShare "\\nas"
or use impersonation in C# code (domain account DOMAIN_B\User1 with password 12345A)

Sort ASP .NET Gridview on related table (prefetchpath) column with LLBLGen Pro

If you have a table Order and a related table Customer, you can sort and filter this data for ASP .NET with LLBLGen pro, as mentioned in the LLBLGen Pro documentation:

// Define result entitycollection
EntityCollection<CustomerEntity> customers = new EntityCollection<CustomerEntity>();

// Define sort (sort result on column "Order.ShipCountry")
SortExpression result = new SortExpression();
result.Add(CustomerFields.Name | SortOperator.Ascending);
result[0].CaseSensitiveCollation = false;

// Define filter by adding relations (= inner join in tsql)
RelationPredicateBucket customerFilter = new RelationPredicateBucket();

// Define filter by adding predicateexpression (= where in tsql)

// Load for all customers fetched their orders.
PrefetchPath2 path = new PrefetchPath2(EntityType.CustomerEntity);

// Get the data
using(DataAccessAdapter adapter = new DataAccessAdapter())
     adapter.FetchEntityCollection(customers, customerFilter, path);

If you forget to add the relations, you might get the exception:

An exception was caught during the execution of a retrieval query: The multi-part identifier "dbo.Customer.Name" could not be bound.. Check InnerException, QueryExecuted and Parameters of this exception to examine the cause of this exception.

This is because there is no inner join on Customer, so Customer.Name does not exist in the query

Delete msi packages before build in Microsoft Visual Studio 2008

Some times Microsoft Visual Studio 2008 will not re-create all *.msi packages when I rebuild all setup projects. Maybe this has something to do with source files not changing?
To get around this problem, I just delete the *.msi pacakge before build with a Pre-Build event.

Select you’re setup project, press F4 to open properties window
In the PreBuildEvent textbox enter:

cd "$(TargetDir)"
del *.msi



Website URL shows router admin page from inside internal network

If you have a domain like http://www.vanlisdonk.nl or https://www.roelvanlisdonk.nl and host these websites on you’re own server. The websites will show the router admin page from inside you’re network.
Changing the windows host file in C:\Windows\System32\drivers\etc, routing the internal ip adres lets say to www.vanlisdonk.nl solves the problem.



The host file on all client pc’s on you’re internal network should look like this:




Setup the US Robotics USR5436 Wireless USB Print Server on Vista x64

I had some trouble installing the US Robotics USR5436 Wireless USB Print Server on a Vista x64 laptop.


During the “User” setup I encountered an err = 1805 AddMonitor Fail error.


During the printer driver port setup, I encountered a AddPort fail error.


However there where 2 ports installed (USB001 Virtual printer port for USB and USB002 Virtual printer port for USB).
Using these port resulted in an error trying to print a test page, but using a TCP/IP port worked for me.

Here is the complete list of steps:
> Connect the US Robotics USR5436 Wireless USB Print Server to an wired UTP cable
> Connect the US Robotics USR5436 Wireless USB Print Server to the printer with an USB cable
> Turn on the printer
> Connect the US Robotics USR5436 Wireless USB Print Server to a standard power outlet
> Download 5436-files.zip
> Extract the zip and run the Autorun.exe
> Click Setup Wizard
> During the setup wizard the ip address of the print server will be shown, write it down.
> Add a printer:
> Start > Control Panel > Printers > Add Printer > Add a local printer


> Check Create a new port and select Standard TCP/IP Port


> Enter the IP address (written down during setup)


> Select Generic network card

> Select you’re printer driver
> The rest of the wizard is “Next Next Finish”

Conclusion: don’t use the USB001 and USB002 ports, just create you’re own TCP/IP port and the printer will just work fine under Windows Vista x64