Pages

5/05/2011

Getting all databases from Sql Server 2005-2008 using c#

This code will help you in getting all databases of Sql Server and show them in the drop down list.

SqlConnection connection = new SqlConnection(connectionstring);

ServerConnection conn = new ServerConnection(connection);
Server myServer = new Server(conn);
foreach (Database db in myServer.Databases)
       ddlDatabases.Items.Add(db.Name);

Note: 'ddlDatabases' is the name of combobox. And db.Name contains the name of the database


4/19/2011

Paging through SQL Server

This query will help you in doing paging through SQL Server. You will need to pass just the starting and ending index and it will return the records..


DECLARE @startingindex int;

DECLARE @endingindex int

set @startingindex=10
set @endingindex=20

select * from Table_Name
where table_id in(

SELECT us.table_id
FROM (SELECT ROW_NUMBER() OVER (ORDER BY table_id) AS Row,
Table_id
FROM Table_Name) us
WHERE Row >@startingindex and Row<@endingindex
)


Twitter Delicious Facebook Digg Favorites More