Sunday, March 9, 2014

asp net FormView DataItemCount always return 0

Precautions
  1. Make sure to call DataItemCount on FormView DataBound Event rather than on Page_Load
  2. Make sure FormView's DefaultMode is set to Edit or Readonly not Insert
 Thanks

Friday, February 14, 2014

EXEC Stored Procedure on a row without cursor

DECLARE @StudentID INT = -1
WHILE (= 1) 
BEGIN
 SELECT TOP 1 @StudentID = StudentId
 FROM Students
 WHERE StudentId > @StudentID
 ORDER BY StudentId
 IF @@ROWCOUNT = 0
  BREAK;
 EXEC dbo.ProcedureName @StudentId
END

Saturday, February 8, 2014

How to see active SQL Server connections for database

Using simple select statements
SELECT 
    DB_NAME(dbid) as DBName, 
    COUNT(dbid) as NumberOfConnections,
    loginame as LoginName
FROM
    sys.sysprocesses
WHERE 
    dbid > 0 AND DB_NAME(dbid) LIkE '{DBNAME}'
GROUP BY 
    dbid, loginame
;
or using stored procedure
sp_who or sp_who

Thursday, January 30, 2014

how to set multiple items are selected in ListBox?

List<string> Authors = new List<string>(new string[] { "Jk Rowling""Morris Mano" });
 
foreach (ListItem item in ListBox1.Items)
{
    if (Authors.Contains(item.Text))
        item.Selected = true;
}

Subquery returning csv written values in a Main Query Column

select 
    categorie, 
    stuff((select ', ' + id
           from table2 t2 where t1.categorie = t2.categorie
           for xml path('')),
          1,2,'') [IDs]
from table1 t1