Tuesday, April 22, 2014

LINQ Case statement within Count asp net c#

var statu = from x in dc.Attendance
            group x by 1 into g
            select new
            {
                ID = g.Key,
                Presents = g.Where(t => t.AttendanceStatus == "Present").Count(),
                Absents = g.Where(t => t.AttendanceStatus == "Absent").Count(),
                Leaves = g.Where(t => t.AttendanceStatus == "Leave").Count(),
            };

Monday, April 21, 2014

unique key based on 2 or more columns in SQl Server 2005 or later

CREATE UNIQUE NONCLUSTERED INDEX IX ON Tbl
(
        Col1  ,
        Col2 ,
 Col3
) WITH( IGNORE_DUP_KEY = OFF)

Breaking out of a nested loop c# aspnet

for (int i = 0; i < 100; i++)
{
    for (int j = 0; j < 100; j++)
    {
        if (exit_condition)
        {
            // cause the outer loop to break:
            i = INT_MAX;
            // break the inner loop
            break;
        }
    }
}

IIS - this configuration section cannot be used at this path (configuration locking?)

For Windows 7

  • Click "Start button"
  • in the search box, enter "Turn windows features on or off"
  • in the features window, Click: "Internet Information Services"
  • Click: "World Wide Web Services"
  • Click: "Application Development Features"
  • Check (enable) the features. I checked all but CGI.


For Windows Server 2012

  • Configure Web Server(IIS) inside roles and features
  • Add all features including dot net framework 4

Thursday, April 17, 2014

How to get name of all tables in ms sql database aspnet c#

public System.Collections.Generic.Dictionary<stringstring> GetAllTables(System.Data.SqlClient.SqlConnection _connection)
{
    if (_connection.State == System.Data.ConnectionState.Closed)
        _connection.Open();
    System.Data.DataTable dt = _connection.GetSchema("Tables");
    System.Collections.Generic.Dictionary<stringstring> tables = new System.Collections.Generic.Dictionary<stringstring>();
    foreach (System.Data.DataRow row in dt.Rows)
    {
        if (row[1].ToString().Equals("BASE TABLE"StringComparison.OrdinalIgnoreCase)) //ignore views
        {
            string tableName = row[2].ToString();
            string schema = row[1].ToString();
            tables.Add(tableName, schema);
        }
    }
    _connection.Close();
    return tables;
}

Wednesday, April 16, 2014

Monday, April 14, 2014

asp net c# crystal report server side printing

Exposing printer settings to the SYSTEM account

When a printer is installed on a computer, its settings are stored in the HKEY_CURRENT_USER registry key. IIS runs under the context of the local SYSTEM account. It has access to the HKEY_USERS registry key, but not to the HKEY_CURRENT_USERS subkey, which is only available to a user logged on to the computer.
By default, no printers are defined in the HKEY_USERS key. You can add them by exporting three keys from the HKEY_CURRENT_USERS key and importing them to the HKEY_USERS key
NoteCaution Incorrectly editing the registry might severely damage your system. Make sure you back up valued data before making changes to the registry.
To make printer settings available to the SYSTEM account:
  1. Check that the current user on the Web server has the required printer(s) installed.
  2. To launch the Registry Editor, type regedit in the Start>Run dialog box and click OK.
  3. Select the HKEY_USERS\.DEFAULT\Software\Microsoft\Windows NT\CurrentVersion key and export the registry key from the File or Registry menu.
  4. Specify a name and location in the Export Registry File dialog box and click Save.
  5. This file provides a backup if you need to restore the registry.
  6. In the HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion key, select the Devices subkey and export the registry key.
  7. Specify the name devices.reg and a temporary location in the Export Registry File dialog box and click Save.
  8. Repeat steps 5 and 6 for the PrinterPorts and Windows subkeys, naming the files printerports.reg and windows.reg.
  9. Open devices.reg in Notepad (do not use TextPad or another editor), replace the string HKEY_CURRENT_USER with the string HKEY_USERS\.DEFAULT (note that there is a dot before DEFAULT), and save the file.
  10. Repeat step 8 for printerports.reg and windows.reg.
  11. Double-click each of the edited files to import them into the registry.
  12. Restart IIS so that the configuration changes take effect.

Best way to iterate over a Dictionary in asp net c#?

foreach (KeyValuePair<int, string> entry in dicObj)
{
   //body
}