Monday, November 26, 2012

Code for calling SSIS package in asp.net using c#


using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Microsoft.SqlServer.Server;
using Microsoft.SqlServer.Dts;
using Microsoft.SqlServer.Dts.Runtime;
using Microsoft.SqlServer.Dts.Runtime.Wrapper;
using Microsoft.SqlServer.Dts.Tasks.ScriptTask;
namespace CallPackage
{
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnexecute_Click(object sender, EventArgs e)
        {
            try
            {
                Microsoft.SqlServer.Dts.Runtime.Application app = new Microsoft.SqlServer.Dts.Runtime.Application();
               Microsoft.SqlServer.Dts.Runtime.Package package = null;
                package =(Microsoft.SqlServer.Dts.Runtime.Package) app.LoadPackage(@"C:\Ajay\Package.dtsx",null,true);
                Microsoft.SqlServer.Dts.Runtime.DTSExecResult results = package.Execute();

                if (results == Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Failure)
                {
                    foreach (Microsoft.SqlServer.Dts.Runtime.DtsError local_DtsError in package.Errors)
                    {

                        Console.WriteLine("Package Execution results: {0}", local_DtsError.Description.ToString());
                        Console.WriteLine();
                    }
                }

            }
            catch (Exception ex)
            {
                string SS = ex.Message;
            }
        }
    }
}

SSIS Package using SQL Server Business Intellegence development Student

Is is used to transfer data in tables of two diffrent database

1.Add Data Flow Task

2.On the Data flow
    A).  Add OLE DB Source:double click and add database source connection string and choose table which need to transfer.
   B).Add OLE DB Destincation :double click and add database destination connection string and choose table in which data need to import.

now just run the application and Both source and destination OLE DB should be green heighlighted.It is a symbol of sucess or if it is showing red the there is error in package.

===============================================

Code for calling package in asp.net using c#



using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Microsoft.SqlServer.Server;
using Microsoft.SqlServer.Dts;
using Microsoft.SqlServer.Dts.Runtime;
using Microsoft.SqlServer.Dts.Runtime.Wrapper;
using Microsoft.SqlServer.Dts.Tasks.ScriptTask;
namespace CallPackage
{
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnexecute_Click(object sender, EventArgs e)
        {
            try
            {
                Microsoft.SqlServer.Dts.Runtime.Application app = new Microsoft.SqlServer.Dts.Runtime.Application();
               Microsoft.SqlServer.Dts.Runtime.Package package = null;
                package =(Microsoft.SqlServer.Dts.Runtime.Package) app.LoadPackage(@"C:\Ajay\Package.dtsx",null,true);
                Microsoft.SqlServer.Dts.Runtime.DTSExecResult results = package.Execute();

                if (results == Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Failure)
                {
                    foreach (Microsoft.SqlServer.Dts.Runtime.DtsError local_DtsError in package.Errors)
                    {

                        Console.WriteLine("Package Execution results: {0}", local_DtsError.Description.ToString());
                        Console.WriteLine();
                    }
                }

            }
            catch (Exception ex)
            {
                string SS = ex.Message;
            }
        }
    }
}


    

Friday, November 23, 2012

How to find invalid characters in sql server


CREATE  FUNCTION  FindInvalidValid( @Name NVARCHAR(100) )

RETURNS BIT

BEGIN

    SELECT @Name = RTRIM(ltrim(@Name))

    IF(@name IS null) OR (@Name = '')

      RETURN 1



    DECLARE @len AS INT

    DECLARE @index AS INT

    DECLARE @ascii AS int

    SELECT @len =  LEN(@Name),@index = 1

    WHILE(@index <= @len)

    BEGIN

      SELECT @ascii = ASCII(substring(@Name,@index,1))

      IF ((@ascii BETWEEN 65 AND 90)

         OR (@ascii BETWEEN 97 AND 122)

         OR (@ascii BETWEEN 193 AND 252)

         OR (@ascii = 32)

         OR (@ascii = 45)

         OR (@ascii = 46)

         OR (@ascii BETWEEN 48 AND 57)

         )

      begin

         SELECT @index = @index + 1

         CONTINUE

      end

      ELSE

         RETURN 0

    END

    RETURN 1

END


================================

now use this query for geeting invalid charactor rows


SELECT *

FROM TracedCompanyDetailsttemp

WHERE dbo.IsNameValid(notes1) = 0

OR dbo.IsNameValid(notes1) = 0

Thursday, November 22, 2012

BCP command for Data moving from SQL server to SQL Azure


For making sql  tables to text data files at local drive

bcp databasename.dbo.Client out E:\Shergroup\SqlData\MoveDataFromSQLAzure.txt -c -U sa -S sherbasefive -P 12456

rk5n5pqf6u.database.windows.net


for coping from local dive text data files to sql azure

bcp databasename.dbo.Client in  E:\Shergroup\SqlData\MoveDataFromSQLAzure.txt -c -U myadmin@rk5n5p -S tcp:rk5n5p.database.windows.net -P c0r=jdb

Wednesday, November 21, 2012

highlighting gridview column cell color in asp.net



protected void GDVHistory_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            string amtsigh = Convert.ToString(DataBinder.Eval(e.Row.DataItem, "Payment_Amt"));
            string minus = amtsigh.Substring(0, 1);
            if (minus == "-")
            {
                e.Row.Cells[2].ForeColor = System.Drawing.Color.Red;
            }

        }
    }

Friday, November 9, 2012

Adding new line after 5 items in list and returning in string using asp.net


1.call method
string PagesNames2 = Convert.ToString( ReturnArrayList(PagesNamesExist));

2.Here is the menthod that adds line break after 5 items

int cnt = 0;
    int warrantIDInt = 0;
    public StringBuilder ReturnArrayList(StringBuilder sb)
    {
        StringBuilder warrantId = new StringBuilder();
        ArrayList warrantIDList = new ArrayList();
        string[] ArryayPageId = sb.ToString().Split(',');
        if (ArryayPageId.Length > 1)
        {
            foreach (string id in ArryayPageId)
            {
                warrantIDList.Add(id);
            }
        }
                         

        if (warrantIDList.Count > 5)
        {
            for (int i = 0; i < warrantIDList.Count; i++)
            {
                string warrantIDStr = warrantIDList[i].ToString();
               
             
                warrantId.Append(warrantIDStr + ",");
                cnt++;
                if (cnt > 5)
                {
                    warrantId.Append("<br/>");
                    cnt = 0;
                }
            }
        }
        else
        {
            for (int i = 0; i < warrantIDList.Count; i++)
            {
                string warrantIDStr = warrantIDList[i].ToString();
                warrantId.Append(warrantIDStr + ",");
            }
        }
        return warrantId;
    }

Thursday, November 1, 2012

How to get selected items value from listbox in c#


if (ListBox1.Items.Count > 0)
        {
            for (int i = 0; i < ListBox1.Items.Count; i++)
            {
                if (ListBox1.Items[i].Selected)
                {
                    string selectedItem = ListBox1.Items[i].Text;
                    //insert command
                }
            }
        }