Ads 468x60px

Wednesday, May 30, 2012

How to write a Stored procedure in SQL-SERVER

Stored Procedure:- Stored Procedure In Sql server can be defined as the set of logically group of sql statement which are grouped to perform a specific task. There are many benefits of using a stored procedure. The main benefit of using a stored procedure is that it increases the performance of the database.The other benefits of using the Stored Procedure is given below:

Benefits of using the Stored Procedure
  1. One of the main benefit of using the Stored procedure is that it reduces the amount of information sent to the database server. It can become more important benefit when the bandwidth of the network is less. Since if we send the sql query (statement)which is executing in a loop to the server through network and the network get disconnected then the execution of the sql statement don't returns the expected results, if the sql query is not used between Transaction statement and rollback statement is not used.
     
  2. Compilation step is required only once when the stored procedure is created. Then after it does not required recompilation before executing unless it is modified and re utilizes the same execution plan whereas the sql statements needs to be compiled every time whenever it is sent for execution even if we send the same sql statement every time.
     
  3. It helps in re usability of the sql code because it can be used by multiple users and by multiple client since we needs to just call the stored procedure instead of writing the same sql statement every time. It helps in reduces the development time.
     
  4. Stored procedure is helpful in enhancing the security since we can grant permission to the user for executing the Stored procedure instead of giving the permission on the tables used in the Stored procedure.
     
  5. Sometime it is useful to use the database for storing the business logic in the form of stored procedure since it make it secure and if any change is needed in the business logic then we may only need to make changes in the stored procedure and not in the files contained on the web server.
How to write a Stored Procedure in SQL Server

Suppose there is a table called tbl_Students whose structure is given below:

CREATE TABLE  tbl_Students

(
    [Studentid] [int] IDENTITY(1,1) NOT NULL,
    [Firstname] [nvarchar](200) NOT  NULL,
    [Lastname] [nvarchar](200)  NULL,
    [Email] [nvarchar](100)  NULL
)
 
Suppose we insert the following data into the above table:
Insert into tbl_Students (Firstname, lastname, Email)
 Values('Vivek', 'Johari', 'vivek@abc.com')

Insert into tbl_Students (Firstname, lastname, Email)
 Values('Pankaj', 'Kumar', 'pankaj@abc.com')

Insert into tbl_Students (Firstname, lastname, Email)
 Values('Amit', 'Singh', 'amit@abc.com')

Insert into tbl_Students (Firstname, lastname, Email)
 Values('Manish', 'Kumar', 'manish@abc.comm')

Insert into tbl_Students (Firstname, lastname, Email)D
 Values('Abhishek', 'Singh', 'abhishek@abc.com')


Friday, May 4, 2012

XAF : Change Listview Default GroupSummary

The following steps will used to change group summary for Listview:
  1. Open model designer by click on application file Model.xafml under YourProject.Web
     
  2. Change GroupSummary Property as shown below:

     
  3. GroupSummary Format Structure {1}:{2},{3}:{4}
    example : TotalPrivateCharge:Sum,TotalPrivateCharge:Sum={0:n2}
     
    1. Property Name
    2. Aggregation Function
    3. Property Name
    4. Aggregation String Format. [Sum={0:n2}]
      1. '0' means first argument which is TotalPrivateCharge
      2. 'n2' means the second argument which is aggregation function value.
    5. Result for this aggregation function is 'Sum=25.12'

Monday, April 30, 2012

XAF : Add Sequence (Serial) Number into a Report

In order to add sequence or serial number such that 1,2,3,4,...etc into a report in devexpress, you should follow the following steps
  • add a Label into a report

  •  Expand Label Tasks dialog

  •  Set Summary Function to Record Number, and Summary Running to Group

Thursday, April 26, 2012

Top Search Tips

At the end of our internet search workshops, participants are asked to come up with a collective top search tips. These can be search tools, individual web sites or search techniques. This is a compilation of the tips from several workshops over the past year.
  1. It isn't your fault! You run your search a second time in Google and you get a completely different set of results, despite having run the same search a mere 20 minutes before. Or you run a site search in Google but the results come from here, there and everywhere. Or your results bear no resemblance whatsoever to your search strategy. Don't worry - it isn't you. Google results are rarely consistent or reproducible from one moment to the next. If you are having serious difficulties getting any sense out of Google, don't struggle. Try another search engine (http://search.yahoo.co.uk), Live (http://www.live.com/), MSE360 (http://www.mse360.com/), Exalead (http://www.exalead.co.uk/)
     
  2. Google Tip 1 highlighted some of the problems with Google but it can still deliver the goods a lot of the time, and it is still the first port of call for most of us. Make sure, though, that you are using the advanced search features to the full and that you are using the right part of Google, for example News for current headlines, Images, Blogsearch etc.
     
  3. Use the Advanced Search screen. There are lots of goodies to be found on the advanced search screens: options for focusing your search by file format (e.g. xls for data and statistics, ppt for expert presentations, pdf for industry or government reports); site and domain search to limit your search to just one web site or a type of organization (e.g. UK government, US academic); and in Google there is a numeric range search.
     
  4. Google Custom Search Engines (Google CSE) at http://www.google.com/coop/cse/. Ideal for building collections of sites that you regularly search, to create a searchable subject list, or to offer your users a more focused search option.
     
  5. See what Google does with your search string. a) If you use the default search box and Google comes back with odd results, click on Advanced Search to see what it has done with your search terms. b) If you use the Advanced Search screen and fill in the boxes, see how Google formats the search strategy by looking the search box at the top of the results page. By learning the commands and prefixes you can build more specific searches on the default search page.

Monday, April 23, 2012

XAF : Show Reports for Individual Views

The Reports module allows you to design reports for a filtered data source. In some scenarios, you may need to preview a report for a certain object or a set of objects that are not related by a criteria. For example, the Invoice business object(s) should be able to be printed in a specific manner. In this case, a specially designed report should be available for display for a particular set of Invoice objects. For this purpose, use the Inplace Reporting feature provided by the Reports module. This topic demonstrates how to use this feature.

To show selected object(s) in a specified report, the Reports module introduces the ShowInReport Action. This Action represents the SingleChoiceAction class instance. Its items represent so-called inplace reports that are designed for the current View's object type.


Wednesday, April 11, 2012

XAF : Override ListView Default Action

In order to override list view default action, you should do the following
  1. Add view controller to your project [i.e. ListViewActionsController]
  2. make class (ListViewActionsController) inherit from DevExpress.ExpressApp.SystemModule.ListViewProcessCurrentObjectController
  3. Override the function.[i.e. ProcessCurrentObject].
The following example present an example for this:

   1:  Imports System
   2:  Imports System.ComponentModel
   3:  Imports System.Collections.Generic
   4:  Imports System.Diagnostics
   5:  Imports System.Text
   6:   
   7:  Imports DevExpress.ExpressApp
   8:  Imports DevExpress.ExpressApp.Actions
   9:  Imports DevExpress.Persistent.Base
  10:   
  11:  Public Class ListViewActionsController Inherits
  12:  DevExpress.ExpressApp.SystemModule.ListViewProcessCurrentObjectController
  13:   
  14:      Public Shared usrname As String
  15:      Public Sub New()
  16:          MyBase.New()
  17:   
  18:          'This call is required by the Component Designer.
  19:          InitializeComponent()
  20:          RegisterActions(components)
  21:   
  22:      End Sub
  23:   
  24:      Protected Overrides Sub ProcessCurrentObject(ByVal e As 
               DevExpress.ExpressApp.Actions.SimpleActionExecuteEventArgs)
  25:          If (e.CurrentObject.GetType.Name = "PhoneHolder" And 
                       View.Id = "CustomHolderListView") Then        
  26:              BillingSystem.Module.sharedMod.currentClickedUsername = 
                                   CType(e.CurrentObject, PhoneHolder).UserName
  27:          End If
  28:   
  29:          MyBase.ProcessCurrentObject(e)
  30:      End Sub
  31:   
  32:  End Class

Thursday, April 5, 2012

XAF : Override DetailedView Action

In order to override detailed view action such as SaveAndClose, you should do the following
  1. Add view controller to your project [i.e. DefaultDetailViewActions]
  2. make class (DefaultDetailViewActions) inherit from WebDetailViewController
  3. Override the function.[i.e. SaveAndClose].
The following example present an example for override SaveAndClose function:

   1:  Imports System
   2:  Imports System.ComponentModel
   3:  Imports System.Collections.Generic
   4:  Imports System.Diagnostics
   5:  Imports System.Text
   6:   
   7:  Imports DevExpress.ExpressApp
   8:  Imports DevExpress.ExpressApp.Actions
   9:  Imports DevExpress.Persistent.Base
  10:   
  11:  Imports DevExpress.ExpressApp.Web.SystemModule
  12:  Public Class DefaultDetailViewActions
  13:      Inherits WebDetailViewController
  14:   
  15:      Public Sub New()
  16:          MyBase.New()
  17:   
  18:          'This call is required by the Component Designer.
  19:          InitializeComponent()
  20:          RegisterActions(components)
  21:   
  22:      End Sub
  23:   
  24:      Protected Overrides Sub SaveAndClose(ByVal args As 
                        DevExpress.ExpressApp.Actions.SimpleActionExecuteEventArgs)
  25:          If args.CurrentObject.GetType.Name = "Calendar" Then
  26:              autoCalendarEntriesAddition(args)
  27:   
  28:          End If
  29:          MyBase.SaveAndClose(args)
  30:      End Sub