Saturday, May 28, 2011

what is view in sql server ?

view is one type of virtual table so view does not contain physical memory.
view is just some columns and rows combination which is selected from one or
more table.just it contain query.
 view benefits :- 
view is provide abstract layer over database tables. it's provide security.
only some non sensitive columns select in query so confidential data can not
appear that particular user.
for example:-
create view view_name select name from tbladmin.    

Saturday, May 21, 2011

using SqlDataAdapter Update table

using System;

using System.Data;

using System.Data.SqlClient;



class UpdateusingdataobjAdapter
{
static void Main()
{
string cn="server=localhost;database=DBTEST;uid=sa;pwd=sa";
SqlConnection Connection = new SqlConnection(cn);
string query = @"select * from tblemp ";
string update = @"update tblemp set name = @name where id = @id";
try
{

   SqlDataobjAdapter objAd = new SqlDataobjAdapter();

   objAd.SelectCommand = new SqlCommand(query, Connection );
   DataSet objDs = new DataSet();  

   objAd.Fill(objDs, "tblemp");
   DataTable objDt = objDs.Tables["tblemp"];

   objDt.Rows[0]["name"] = "Ravi";

   foreach (DataRow row in objDt.Rows)
   {

    Console.WriteLine(

                  "{0} {1}",

                  row["name"].ToString(),

                  row["lastname"].ToString();

            }



     // Update tblemps

    SqlCommand objcmd = new SqlCommand(update, Connection );

    objcmd.Parameters.Add("@name",SqlDbType.NVarChar,15, "name");

    SqlParameter parm = objcmd.Parameters.objAdd("@id",SqlDbType.Int,4,"id");

    parm.SourceVersion = DataRowVersion.Original;

    objAd.UpdateCommand = objcmd;

    objAd.Update(objDs, "tblemp");

    }
catch(Exception e)
 {

            Console.WriteLine("Error: " + e);

 }
finally
 {

            Connection.Close();

 }

      } 

   }

Friday, May 20, 2011

Using Store Procedure customize Paging in GridView Data Control

On web 1000 of records are in Database.We need only small amount 
of data i.e 10,15 etc. default paging all records are load and
it take more time. Performance of our Application decreasing. 
we create custom Optimize Paging.
In this paging we retrieve only our page size data only from database 
for that we create store procedure.
Customize or Manual Paging Store procedure     
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:  <Author,,ASPdotNet-Example.blogspot.com>
-- Create date: <Create Date,,May 20 2011>
-- Description: <Description,,>
-- =============================================
CREATE PROCEDURE [dbo].[SP_Paging]
@PageIndex int,
@PageSize int,
@TotalRecord int output,
AS
BEGIN
 
 SET NOCOUNT ON;
select @TotalRecord=count(id) from tblemp
 
select * from 
(
select row_number() over (order by [id] asc )as RowNumber,
Name,depid,Salary from tblemp
)as a 
where a.rownumber between (@PageIndex-1)*@PageSize+1 AND 
(((@PageIndex-1)*@PageSize+1)+@PageSize)-1
END