Wednesday, September 25, 2013

Cannot resolve the collation conflict In LINQ

Cannot resolve the collation conflict IN LINQ Can be resolved using AsEnumerable() with Table Like as mention below



 DataClassesDataContext tdc = new DataClassesDataContext();

        var  warid = (from id in tdc.SP_Cases.AsEnumerable()
                      join defe in tdc.Defendant_Masters.AsEnumerable() on id.WarrantID   equals defe.WarrantID
                      join defAd in tdc.Defendant_Addresses.AsEnumerable() on defe.CID equals defAd.Def_Id
                     where id.WarrantID == "SPC1080"
                     select new { id.WarrantID, id.JudgCost, id.EntryDate,defe.DefendantName,defAd.Add1 }).FirstOrDefault();

        if (warid != null)
        {
            Label1.Text = warid.WarrantID;
            Label2.Text = warid.JudgCost.ToString();
            Label3.Text = warid.DefendantName;
            Label4.Text = warid.Add1;
        }

Tuesday, September 24, 2013

Error executing child request for ChartImg.axd

While working working with MS Chart control in .net 3.5,i am getting following error :
"Error executing child request for ChartImg.axd " and it is solved by following steps:

Add in webconfig 

1.Add chart image saving folder name as
<appSettings>
 <add key="ChartImageHandler" value="storage=file;timeout=20;dir=C:\TempImageFiles\;" /></appSettings>

2. add http handler as:

<httpHandlers>
  <add path="ChartImg.axd" verb="GET,HEAD" type="System.Web.UI.DataVisualization.Charting.ChartHttpHandler, System.Web.DataVisualization, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" validate="false" />
</httpHandlers>

3.Add Handler as

<handlers>
  <add name="ChartImageHandler" preCondition="integratedMode" verb="GET,HEAD,POST" path="ChartImg.axd" type="System.Web.UI.DataVisualization.Charting.ChartHttpHandler, System.Web.DataVisualization, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
</handlers>


4.Make sure you need to add Chart Image save location(ImageLocation) tag in Chart control as:

 <asp:Chart ID="Chart2" runat="server"  Height="536px" Width="680px" ImageStorageMode="UseImageLocation" ImageLocation="TempImageFiles/ChartPic_#SEQ(300,3)" EnableViewState="true">
                        <Titles>
                        <asp:Title Name="Title1" Text="Enforceble Pie" 
                        Alignment="TopCenter" Font="Verdana, 12pt, style=Bold" ForeColor="Purple">
                        </asp:Title>
                        </Titles>
                        <Series>
                        <asp:Series Name="Series1" ChartType="Pie" CustomProperties="PieLabelStyle=outside, CollectedThresholdUsePercent=False, PieLineColor=Purple" Legend="Legend1"   >
                        </asp:Series>

                        </Series>
                        <Legends>
                        <asp:Legend Name="Legend1" BackImageAlignment="Bottom" Docking="Bottom" 
                                Font="Verdana, 7.25pt" IsTextAutoFit="False"  >
                        </asp:Legend>

                        </Legends>
                        <ChartAreas>
                        <asp:ChartArea Name="ChartArea1" >
                        </asp:ChartArea>
                        </ChartAreas>
                        </asp:Chart>
            












Thursday, September 19, 2013

How to pass logon information to reportdocument object to export in pdf from crystal report in sqlsever2005/2008 and Sql Aure



 logon information to reportdocument object in sqlsever2005/2008




ReportDocument repDoc = new ReportDocument();
   repDoc.Load(repFilePath);

// This is for  logon information to reportdocument object in sqlsever2005/2008
 repDoc.SetDataSource(getCustomerData(clientid));
  repDoc.SetDatabaseLogon("userid", "Password", "Sever Name", "Database name");
  repDoc.SetParameterValue(0, clientid);

//  logon information to reportdocument object in Sql Azure

repDoc.SetDataSource(getCustomerData(clientid));
  repDoc.DataSourceConnections[0].SetConnection("ServerName", "database Name", "User ID", "Password");
   repDoc.DataSourceConnections[0].SetLogon("User id", "Password");
                 
   repDoc.SetParameterValue(0, clientid);


 // Stop buffering the response
                    Console.Clear();
                 
                    ExportOptions CrExportOptions;

                    DiskFileDestinationOptions CrDiskFileDestinationOptions = new DiskFileDestinationOptions();
                    PdfRtfWordFormatOptions CrFormatTypeOptions = new PdfRtfWordFormatOptions();
                    CrDiskFileDestinationOptions.DiskFileName =  filePathName + ".pdf";
                    CrExportOptions = repDoc.ExportOptions;
                    {
                        CrExportOptions.ExportDestinationType = ExportDestinationType.DiskFile;
                        CrExportOptions.ExportFormatType = ExportFormatType.PortableDocFormat;
                        CrExportOptions.DestinationOptions = CrDiskFileDestinationOptions;
                        CrExportOptions.FormatOptions = CrFormatTypeOptions;

                    }
                    repDoc.Export();



        // Business layer class to get the data from database
        private DataSet getCustomerData(string clientid)
        {

            SqlConnection con = new SqlConnection(ConfigurationSettings.AppSettings["SherpaSQLConnString"].ToString());
            SqlCommand cmd = new SqlCommand("ClientMIPage1", con);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.Add(new SqlParameter("@cclientid", SqlDbType.VarChar, 36));
            cmd.Parameters[0].Value = clientid;
            DataSet ds = new DataSet();
            SqlDataAdapter da = new SqlDataAdapter();
            da.SelectCommand = cmd;
            da.Fill(ds);
            return ds;

        }


Friday, August 16, 2013

Use of COALESCE in SQL Server

 use of COALESCE in SQL Server?




declare @i varchar(500)
select @i=COALESCE(@i,RoleTitle)+','+RoleTitle from ProfileMaster

print @i

result is :

Administrator,Administrator,EO,Admin Team,Agent,Print Queue User,Client

Thursday, June 13, 2013

Piovt using sql query

SELECT * FROM (SELECT
convert(char(3), transaction_timestamp, 0) as transaction_timestamp1,transaction_serviceType FROM transactions_history 
where transaction_timestamp >='2013-01-01 00:00:00' and  transaction_timestamp<='2013-06-11 23:59:00'
and transaction_status in('OK'))
as PV
PIVOT
(
      count(transaction_timestamp1)
      --COUNT(transaction_serviceType)
      FOR transaction_timestamp1 IN ([JAN],[FEB],[MAR],[APR],[MAY],[JUN])
)

AS PVT 

and output would be as mention below:


transaction_serviceType JAN   FEB   MAR   APR   MAY   JUN
Sherforce               43    48    46    44    27    7
SherforcePlus           3     2     3     1     1     1
Shergroup Enforcement   2     6     2     13    16    16
ShergroupLegal          0     4     0     2     0     0

Thursday, May 30, 2013

Sql function for Proper case

Create function properCase(@string varchar(8000)) returns varchar(8000) as    
begin    
 if len(@string)>0  
 begin  
        set @string = lower(@string)    
        declare @i int    
        set @i = ascii('a')    
        while @i <= ascii('z')    
        begin    
               set @string = replace( @string, ' ' + char(@i), ' ' + char(@i-32))    
               set @i = @i + 1    
        end    
        set @string = char(ascii(left(@string, 1))-32) + right(@string, len(@string)-1)    
 end  
        return @string    
end

call this funcrion as :

select dbo.ProperCase('AJAY')

result is:
Ajay

Wednesday, May 29, 2013

Code for merging serveral PDF into single PDF in asp.net

For merging PDF into single PDF we need to include  namespace  mention below

using iTextSharp.text;
using iTextSharp.text.pdf;

and for it you need to add reference of ItextSharp DLL.

Now use this function for merging PDF.....


public  void MergeFiles(string destinationFile, string[] sourceFiles)
    {
        try
        {
            int f = 0;
            // we create a reader for a certain document
            PdfReader reader = new PdfReader(sourceFiles[f]);
            // we retrieve the total number of pages
            int n = reader.NumberOfPages;
            //Console.WriteLine("There are " + n + " pages in the original file.");
            // step 1: creation of a document-object
            Document document = new Document(reader.GetPageSizeWithRotation(1));
            // step 2: we create a writer that listens to the document
            PdfWriter writer = PdfWriter.GetInstance(document, new FileStream(destinationFile, FileMode.Create));
            // step 3: we open the document
            document.Open();
            PdfContentByte cb = writer.DirectContent;
            PdfImportedPage page;
            int rotation;
            // step 4: we add content
            while (f < sourceFiles.Length)
            {
                int i = 0;
                while (i < n)
                {
                    i++;
                    document.SetPageSize(reader.GetPageSizeWithRotation(i));
                    document.NewPage();
                    page = writer.GetImportedPage(reader, i);
                    rotation = reader.GetPageRotation(i);
                    if (rotation == 90 || rotation == 270)
                    {
                        cb.AddTemplate(page, 0, -1f, 1f, 0, 0, reader.GetPageSizeWithRotation(i).Height);
                    }
                    else
                    {
                        cb.AddTemplate(page, 1f, 0, 0, 1f, 0, 0);
                    }
                    //Console.WriteLine("Processed page " + i);
                }
                f++;
                if (f < sourceFiles.Length)
                {
                    reader = new PdfReader(sourceFiles[f]);
                    // we retrieve the total number of pages
                    n = reader.NumberOfPages;
                    //Console.WriteLine("There are " + n + " pages in the original file.");
                }
            }
            // step 5: we close the document
            document.Close();
           
        }
        catch (Exception e)
        {
            string strOb = e.Message;
        }
    }
    public int CountPageNo(string strFileName)
    {
        // we create a reader for a certain document
        PdfReader reader = new PdfReader(strFileName);
        // we retrieve the total number of pages
        return reader.NumberOfPages;
    }


Calling of above function.....

 MergeFiles(ConfigurationManager.AppSettings["ReportPDFMergepath"].ToString() + "ClientMI-" + filePathName + ".pdf", sourceFiles);