Thursday, July 11, 2013

sql pivot query

 IF @OperationId=3
       BEGIN 
      
     --  Declare @district_Name varchar(50)='Sanand'
        Declare @ActYrs varchar(20)
        Set @ActYrs=(Select ActiveYear from LevelControl
        Where ControlId=1 and (Level_1=1 or Level_2=1 or Level_3=1))
        Select *   into #TempLeve9
        From
        (Select Category,Candidates,ActiveYear,district ,CandidateClass from RuleSetFilter) as p
        PIVOT
        (
            sum(Candidates) for Category In([M & HCV Key Acc Customer],[M & HCV Other],[LCV],[SCV-Ace],[SCV-Magic])
        ) as pvt
       
        Where ActiveYear=@ActYrs AND district=@district_Name
        Order By  pvt.district   
       
      --======================================================================================
 
        Select district ,Present_Class_In_School,[M & HCV Key Acc Customer] as 'M & HCV Key Acc Customer1' ,[M & HCV Other] as 'M & HCV Other1' ,[LCV] as 'LCV1' ,[SCV-Ace] as 'SCV-Ace1' ,[SCV-Magic] as 'SCV-Magic1' into #TempLevel0
        From
        (Select COUNT( a.[Lev0Id]) as 'Totpp', a.Vehicle_Category , b.district , a.Present_Class_In_School from Level0Data  as a inner join RuleSetFilter as b
            on a.Vehicle_Category=b.Category 
            Where a.district_id=(select district_id from tbl_mst_district where district_name=@district_Name)
        group by Vehicle_Category , b.district , a.Present_Class_In_School) as d
        PIVOT
        (
            sum(Totpp)  for Vehicle_Category   In([M & HCV Key Acc Customer],[M & HCV Other],[LCV],[SCV-Ace],[SCV-Magic])
        )as pvt
  
  --select * from #TempLevel0
  --select * from #TempLeve9
  --drop table  #TempLevel0
  --drop table #TempLeve9
 
 
  select #TempLeve9.district as district ,
  #TempLeve9.[M & HCV Key Acc Customer],
  #TempLeve9.[SCV-Ace] ,
  #TempLeve9.[M & HCV Other],
  #TempLeve9.[SCV-Magic],
  #TempLeve9.[LCV],
  #TempLeve9.[ActiveYear],
  #TempLeve9.[CandidateClass],
  #TempLevel0.[M & HCV Key Acc Customer1],
  #TempLevel0.[SCV-Ace1] ,
  #TempLevel0.[M & HCV Other1],
  #TempLevel0.[SCV-Magic1],
  #TempLevel0.[LCV1]
 
 
   from    #TempLeve9 left join #TempLevel0 
  on #TempLeve9.district=#TempLevel0.district
  AND #TempLeve9.CandidateClass=#TempLevel0.Present_Class_In_School
 
 
 
    END

Saturday, June 29, 2013

Insert Data In Sql Server(Integer Value)

ASPX.CS Page

 int Admin = ObjUser.insert_Admin(1, Convert.ToString(dropUserType.SelectedValue), Convert.ToString(txtUsername.Text));

BLL CLASS PAGE

 public int insert_Admin(int OperatorId, string UserRoll, string UserName)
       {
           SqlParameter[] param = new SqlParameter[3];

           param[0] = new SqlParameter("@OperatorId", SqlDbType.Int);
           param[0].Direction = ParameterDirection.Input;
           param[0].Value = OperatorId;

           param[1] = new SqlParameter("@UserRoll", SqlDbType.VarChar,200);
           param[1].Direction = ParameterDirection.Input;
           param[1].Value = UserRoll;

           param[2] = new SqlParameter("@UserName", SqlDbType.VarChar, 200);
           param[2].Direction = ParameterDirection.Input;
           param[2].Value = UserName;

         
                 

           int dt = objdb.Insert_Update_Del("sp_Master_User", param);

           return dt;


       }

DLL CLASS PAGE

  public Int32 Insert_Update_Del(string SP_Name, SqlParameter[] param)
        {

            DoConnection();

            SqlCommand cmd = new SqlCommand(SP_Name, Con);
            cmd.CommandType = CommandType.StoredProcedure;

            if (param.Length > 0)
            {
                for (int i = 0; i < param.Length; i++)
                {
                    cmd.Parameters.Add(param[i]);
                }
            }

            Int32 intvel = cmd.ExecuteNonQuery();
            return intvel;


        }

STORE PROCEDURE IN SQL SERVER

CREATE PROCEDURE [dbo].[sp_Master_User]
  
     @OperatorId int = NULL ,   
     @UserRoll(200) = NULL,
     @UserName(200) = NULL
    
  
    
  
AS
BEGIN
  
  
if @OperatorId = 1
begin
insert into dbo.Master_User

(
    UserRoll,
    UserName
  

)



values

(
    @UserRoll,
    @UserName
 



)
          
end   

END

calendar control in asp.net

<%@ Register assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" tagprefix="asp" %>






<tr>
            <td class="style2">
                Contract Start Date</td>
                                            <td>
                                                <asp:TextBox ID="TextBox17" runat="server" Width="175px"></asp:TextBox>
                                                <asp:ImageButton ID="ImageButton1" runat="server" Width="16px"
                                                    ImageUrl="~/images/Calendar.png" onclick="ImageButton1_Click" />
                                              
                                                
                                                <asp:Panel ID="Panel2" runat="server">
                                                 <asp:Calendar ID="Calendar1" runat="server" Width="80px" 
          onselectionchanged="Calendar1_SelectionChanged" ></asp:Calendar>

                                                </asp:Panel>
                                                                                              
                                                <asp:RequiredFieldValidator ID="RequiredFieldValidator17" runat="server"
                        ControlToValidate="TextBox17" ErrorMessage="Please Fill Contract Start Date" Display="Dynamic"
                                                    ValidationGroup="1"></asp:RequiredFieldValidator>
                                                 <br />
        <asp:CalendarExtender ID="calendarButtonExtender" runat="server" TargetControlID="TextBox17"
            PopupButtonID="Image1" />
                                            </td>
                                        </tr>

Thursday, June 27, 2013

Connect With Sql Server


Web Config



<appSettings>
    <add key ="ConnectDB" value ="Data Source=xxxxxx;Initial Catalog=xxxxxxxx;User ID=xxxxxxxxxxx;Password=xxxxxxxxxx"/>
   
  </appSettings>











DLL CLASS



 public class ClsDB
    {

        SqlConnection Con = new SqlConnection(ConfigurationSettings.AppSettings["ConnectDB"]);
        public void DoConnection()
        {
            if ((Con.State == ConnectionState.Closed) || (Con.State == ConnectionState.Broken))
            {
                Con.Open();
            }
        }
}