December 31, 2011

Execute package in Asp.Net


Add DLL:        

Microsoft.server.SqlServer.ManageedDTS


   string serverFileName = Path.GetFileName(fpUploadIncome.PostedFile.FileName);
                fpUploadIncome.PostedFile.SaveAs(MapPath("~//UploadedFiles/") + serverFileName);

                string path = Path.GetFullPath(fpUploadIncome.PostedFile.FileName);


                Microsoft.SqlServer.Dts.Runtime.Application app = new Application();
                Package oPack = null;
                Variables oVar;
                oPack = app.LoadPackage(@"C:\Package\uploadIncome.dtsx", null);
                oVar = oPack.Variables;
                oVar["FilePath"].Value = "C:\\income.xls";
                oVar["FilePath"].Value = path.Trim().ToString();

                Microsoft.SqlServer.Dts.Runtime.DTSExecResult Results = oPack.Execute();
                //Microsoft.SqlServer.Dts.Runtime.DTSExecResult Results = oPack.Execute(null, oVar, null,null, null);
                if (Results == DTSExecResult.Success)
                {
                    //msgDetails.Show(MyMessageBox.MessageType.Success, "Data uploaded succssfully");
                    //Execution Success
                }
                else
                {
                    //msgDetails.Show(MyMessageBox.MessageType.Success, "Error while uploading file");
                    // excution fails
                }
             

December 30, 2011

Creating and Deploying a manifiest file in SSIS


Creating a Deployment Manifest

  • With the Solution Explorer open Right-Click on the project name and click Properties
  • This will open the Project Properties Pages 
  • Select the Deployment Utility from the page
  • Change the CreateDeploymentUtility property to True

December 28, 2011

Get Start date of Current month

SELECT Convert(datetime , CONVERT(VARCHAR(25),DATEADD(dd,-(DAY(Getdate())-1),' Getdate() ),103),103) AS Date_Value 

December 27, 2011

Delete temporary table from Tempdb


 IF OBJECT_ID('tempdb..# temp ') IS NOT NULL    
 BEGIN    
   DROP TABLE #temp  
 END      

December 17, 2011

Gridview button Row Command

<asp:BoundField DataField=
</asp:BoundField>


protected
{
void gvIPOReport_RowCommand(object sender, GridViewCommandEventArgs e)if
{
(Session["UserId"] != null)if
{
GridViewRow row = (GridViewRow)(((ImageButton)e.CommandSource).NamingContainer);
(e.CommandName == "DeleteRow")string ApplyId = gvIPOReport.DataKeys[row.RowIndex].Value.ToString();string IssueCode = gvIPOReport.Rows[row.RowIndex].Cells[13].Text.ToString(); // Column 13 is HeaderText = "Issuecode">DataAccess oData = new DataAccess();int iCount = oData.DeleteApplicationDetails(ApplyId, Session["UserId"].ToString().Trim().ToUpper(), IssueCode);if
{
rowErrorMessgage.Visible =
lblErrorMessage.Text =
}
(iCount > 0)false;"Record Deleted Successfully.";else{
}
}
}
else{
lblErrorMessage.Text =
"Session Expired Please login again."
}
;
"IssCode" Visible = "False" HeaderText = "Issuecode">

C# Code to download the file

using

{




System.IO;private void DownloadFile(string fname, bool forceDownload)string path = MapPath(@"~\Forms\" + fname);string name = Path.GetFileName(path);string ext = Path.GetExtension(path);string type = "";// set known types based on file extension
{

{


type =


type =



type =

}
}

{
Response.AppendHeader(
}


Response.ContentType = type;
Response.WriteFile(path);
Response.End();
}


{
DownloadFile(
}
if (ext != null)switch (ext.ToLower())case ".htm":case ".html":"text/HTML";break;case ".txt":"text/plain";break;case ".doc":case ".rtf":"Application/msword";break;if (forceDownload)"content-disposition", "attachment; filename=" + name);if(type != "")protected void imgMoblileAdd_Click(object sender, ImageClickEventArgs e)"filename.pdf", true);

Javascript validation for Dropdown list

if (ddlType.options[ddlType.selectedIndex].text == "Select Type")
{
   alert( 'Please Select');
            ddlType.focus();
            return false;
}

December 16, 2011

last date of previous month from todays date

Select DATEADD(day,-1,DATEadd(MONTH,datediff(month,0,getdate()),0)) 

Get financial year from Todays date



DECLARE @StartDate DATETIME
DECLARE @TodaysDate DATETIME

SELECT @TodaysDate = CONVERT(DATETIME, CONVERT(CHAR(10),  Getdate(), 101), 101)

--If it is April 1 or greater, then the StartDate is the current year
IF MONTH(@TodaysDate) >= 4  SELECT @StartDate = CONVERT(CHAR(4), YEAR(@TodaysDate)) + '0401'
--Otherwise, it's the previous year
ELSE SELECT @StartDate = CONVERT(CHAR(4), YEAR(@TodaysDate)-1) + '0401'

SELECT @StartDate AS StartDate, @TodaysDate AS EndDate