11 August 2014

How to find out the SQL Server installation date?



SELECT create_date as 'Installation Date' FROM sys.server_principals WHERE name='NT AUTHORITY\SYSTEM'

9 August 2014

How to find all printers in your Active Directory



         private void FindAllPrinters()
           {
               string[] wantedProps = { "name", "servername", "printername",
                                          "drivername", "shortservername", "location" };
    
               var ds = new DirectorySearcher { Filter = "(objectClass=printqueue)" };
               foreach (SearchResult sr in ds.FindAll())
               {
                   Debug.WriteLine(sr.Path);
                   ResultPropertyCollection rpc = sr.Properties;
    
                   // use rpc.PropertyNames instead of wantedProps if you want to
                   // know more about the printers than is provided below
                   foreach (string property in wantedProps)
                   {
                       foreach (object value in rpc[property])
                           Debug.WriteLine(string.Format("\t{0}: {1}", property, value));
                   }
               }
           }

loop through a table in SQL Server

Create table

CREATE TABLE tbl_Sample
(
     ID      int identity (1,1)
    ,Name    varchar(50)
)

Loop through Code

DECLARE @minID int
 -- get the first record
SELECT @minID = min(ID) FROM tbl_Sample
 -- loop until we have no more records
WHILE @minID is NOT NULL
BEGIN
    -- do actual work, for instance, get the Name and Address for this ID
    SELECT Name FROM tbl_Sample WHERE ID = @minID
     -- get the next record
    SELECT @minID = min(ID) FROM tbl_Sample WHERE @minID < ID
END

28 July 2014

How to set first row color to gridview in c#



protected void gv1_RowDataBound(object sender, GridViewRowEventArgs e)
  {
      try
       {
                if (e.Row.RowIndex == 0)
                {
                    e.Row.BackColor = System.Drawing.Color.YellowGreen;

                }
       }
       catch (Exception ex)
       {
          lbl_error.Visible = true;
          lbl_error.ForeColor = System.Drawing.Color.Red;
          lbl_error.Text = ex.Message;
              
       }

  }

8 July 2014