Tuesday, December 21, 2010

Inline Table-valued Function in SQL server for optimized result.

Sometime we want to parameterize our view for getting the optimized result, but we cannot pass the parameter to view. In this case we can use inline table valued parameterize function which will return the "Table". We can use this table in joins, sql queries, stored procedures and anywhere like as normal table.
First we will create view and see the result and time taken by view. Then after we will create the function which returns table with a parameter.
Code


View
create view GetAllDatabyCountry
as
select product.productid,product.productname,product.code,product.productPrice
   ,country.countryname,city.cityname
   from product
   left outer join
   country on product.countryid=country.countryid
   left outer join
   city on product.cityId=city.cityId
   



Function
Create function GetDatabyCountryId(@countryId int)
returns table
as
return (
   select product.productid,product.productname,product.code,product.productPrice
   ,country.countryname,city.cityname
   from product 
   left outer join
   country on product.countryid=country.countryid
   left outer join
   city on product.cityId=city.cityId
   where country.countryid=@countryId
  )


Using Function in Query
create procedure getDataByCountryId
@countryId int
as
begin
select getDataBycountry.* from  dbo.GetDatabyCountryId(@countryId) as getDataBycountry
end

Wednesday, December 15, 2010

Validate checkbox in ASP.NET

You can validate check box or any custom control by using "CustomValidator" and javascript.
 
 Check box in your aspx page
  
   
   
     *
 

Friday, December 3, 2010

Sharing settings specified in appSettings element across multiple projects in .NET.

When you are developing multiple .NET projects and want to share common custom configuration settings specified in the
element, for this you can create a common setting file for your all .NET projects.
In web.config file in you can use file attribute like this.

  
  
Code
Web.config file


 


  
  
    
    

    

settings.config file