Saturday, July 14, 2012

ADO.NET Entity Framework

Entity Framework

What is Entity Framework?
                It is an Object/Relational mapping framework which helps/ enables developers to work with relational data as an domain specific objects.

What it exactly Mean:
 Suppose a developer needs to write a code to create/ edit and delete and customer information, he creates stored procedures in the database, and he writes the code to calls this procedures with relevant parameters.

If he needs to support more than one database, they need to write different code (database specific) to execute these stored procedures.

What if suppose we have option to access different database with single set of code and also no need to worry much about database connectivity and access??....... That’s what entity framework does.

Since the entity framework integrated with LINQ, we (developer) can issue all queries in the code to do the database operation.  With these features we can now concentrate more on writing business logic instead of spending time on relational data.

Since the entity framework built on provider model, with existing provider being updated additively to support this entity framework, the developer can easily migrate/ upgrade the application built on to entity framework.

Some of the Capabilities of Entity Framework:

a.       It supports major database servers.

b.      It can handle real-world database schemas and Stored procedures

c.       Its visual studio integrated features provides option to generate models automatically.

d.      It is integrated with, WCF, WPF and WCF data services

Some of the high level benefits:

a.       Reduces the development time spending on database access

b.      No need to write different database access code for different databases

c.       Database object schema can be changed without doing changes in the code
Architecture of Entity Framework:

Monday, July 9, 2012

Add Custom Code in SSRS

How to Add Custom Code in SSRS

1.       Create a new .rdl file open it
2.       Open the report and In the Design view, right-click the design surface outside the border of the report and click Report Properties.
3.       Click Code.
4.       In Custom code, type the code. Errors in the code produce warnings when the report runs. The following example creates a custom function named AddPrefix. (Code should be written in vb)
Public Function AddPrefix (ByVal s As String) As String 
Return “INV00” + s

End Function

5.       Use the below code to use this function in your report
=Code. AddPrefix(Fields!InvoiceCode.Value)

Sunday, July 8, 2012

SQL Server 2012 Build-In Functions

Calculates the average of the Values in a Group.
AVG (<>)
ALL  OR DISTINCT keyword can be used before the <> to get Average based on all values or Distinct values
Select AVG(Math_Marks) From StudentMarks Group By Sections

Gives no of items in a group
COUNT (<>/ *)
ALL  OR DISTINCT keyword can be used before the <> to get count of all values or Distinct values
Select Count(Student) From StudentMarks Group By Sections

Increasing the Size of SQL Server 2012 DB

USE master;
    (NAME = testdbdat,
    SIZE = 50MB);
This command will increase the database TestDb data file to 50MB.

Sunday, July 1, 2012

Installshield Script Custom Dialog

Here is the process I take for handling Custom Dialog boxes
1. Switch to Dialog under User Interface
2. Create your custom dialog box with all its controls the way you need it.
3. Swtich to direct editor and select the Dialog table.
4. When you created your dialog you could specify the name you want for the dialog. That name should appear in this table.
5. Find that name and then scroll all the way to the right. The very last column contains the ID.
6. It seems that the default for this ID is 0 (unless I am doing something wrong). Change it to a number that does not conflict with existing dialogs. I usually use numbers in the 13000 range. What value you specify here you have to now define in your script.

Here is how I handle defining my dialogs.
1. Create a CustomDialogs.h file (the name does not matter).
2. In this .h file create prototypes and defines for each dialog and their controls.

prototype License();
prototype AbbrevLicense();
prototype NUMBER FrameWorkRegDlg();
prototype NUMBER PhoneRegDlg();
//define dialog IDs
#define RES_DIALOG_ID 13051
#define LICENSE_DIALOG_ID 13035

//define controls for dialogs
//Control IDs
#define RADIO1 1000
#define RADIO2 1005
#define RADIO3 1010

#define CHECKBOX1 1100
#define CHECKBOX2 1105
#define CHECKBOX3 1110

#define TEXT1 3000
#define TEXT2 3005
#define TEXT3 3010

#define COMBO1 7000
#define COMBO2 7005

3. Create a CustomDialogs.rul file (name does not matter) and define your functions.

// Function: DriverInstall
// Purpose: Custom Dialog requiring user to choose from 2 radio buttons. Large
// text description boxes above and below radio buttons.
function DriverInstall(sMsg, sRadioOne, sRadioTwo)
STRING szDialogName;
HWND hDlg;
BOOL bBasicOnly;
NUMBER nReturn;

// Specify a name to identify the custom dialog in this setup.
szDialogName = "CustomDialog";

// Define the dialog. Pass a null string in the second parameter
// to get the dialog from _isuser.dll or _isres.dll. Pass a null
// string in the third parameter because the dialog is identified
// by its ID in the fourth parameter.
nResult = EzDefineDialog(szDialogName, "", "", TEXT2_RADIO2);

if (nResult < 0) then
// Report an error; then terminate.
MessageBox ("Error in defining dialog", SEVERE);

// Initialize the indicator used to control the while loop.
bDone = FALSE;

// Loop until done.

// Display the dialog and return the next dialog event.
nCmdValue = WaitOnDialog(szDialogName);

// Respond to the event.
switch (nCmdValue)

case 2, DLG_CLOSE:
Do(EXIT); // The user clicked the window's close button.

case DLG_ERR:
MessageBox ("Dialog failed.", SEVERE);
bDone = TRUE;

case DLG_INIT: ;
// No initialization is required for this example.
CtrlSetState(szDialogName, RADIO1, BUTTON_CHECKED);
CtrlSetText(szDialogName, TEXT1, sMsg);
CtrlSetText(szDialogName, TEXT2, ""); //Second text box is not used, so set it to empty string.
CtrlSetText(szDialogName, RADIO1, sRadioOne);
CtrlSetText(szDialogName, RADIO2, sRadioTwo);

hDlg = CmdGetHwndDlg(szDialogName);
SetWindowText(hDlg, "Driver Option"); // Set the window title. Defined in Winsub.rul.

if (CtrlGetState(szDialogName, RADIO1) = BUTTON_CHECKED) then
bInstDriver = FALSE;
elseif (CtrlGetState(szDialogName, RADIO2) = BUTTON_CHECKED) then
bInstDriver = TRUE;

bDone = TRUE;

case SD_PBUT_EXITSETUP: //Cancel button

EndDialog(szDialogName); // Close the dialog box.
ReleaseDialog(szDialogName); // Free the dialog box from memory.
return BACK;

case SD_PBUT_CANCEL: //Esc key


until bDone;

// Close the dialog box.
// Free the dialog box from memory.


Source :