Wednesday, February 20, 2013

how to change collation in sql server 2008 r2


ALTER TABLE dbo.Defendant_master ALTER COLUMN WarrantID
            varchar(36)COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL

Monday, February 18, 2013

Row_Number() in sql


Select ROW_NUMBER()
        OVER (ORDER BY  columnName) AS Rownum from abc

how to change row data in column and display in gridview cell in asp.net


1. using sql query add CHAR(13) in various column and it will display like below text

    12 street town CLEVELAND pcode

2. Now  on GVLetter_RowDataBound event replace spcace with line break(<BR/>) as mention below

protected void GVLetter_RowDataBound(object sender, GridViewRowEventArgs e)
    {
       
        int id;
        if (e.Row.RowType == DataControlRowType.DataRow)
        {

            e.Row.Cells[1].Text = e.Row.Cells[1].Text.Replace("\r", "<br />");
            e.Row.Cells[2].Text = e.Row.Cells[2].Text.Replace("\r", "<br />");

            id = Convert.ToInt32(e.Row.Cells[4].Text);
            if (id == 100)
            {
                ((ImageButton)e.Row.FindControl("ImagConfirm")).Visible = true;

            }
            else
            {
                ((ImageButton)e.Row.FindControl("ImagConfirm")).Visible = false;
            }
        }
    }

Result in griedview cell will as mention below


12
street
town
CLEVELAND
pcode

Monday, February 11, 2013

code for catching error and saving in database in asp.net


 void Application_Error(object sender, EventArgs e)
    {
        //Code that runs when an unhandled error occurs
     
        //PS: This functionality stores all errors in database and these errors can be vieved
        //directly in database in 'ErrorLog' table. Or can also be viewed by browsing the
        //page 'errorlog.aspx' directly from the root of application.
     
        //Note: This logic will failed only in the case;
        //if database connection will not established due to some reasons.
        //so this is single case and can be trapped by developers. OR
        //In web.config; set <customErrors mode="Off"> and see the error.

        clsGenericClass objGen = new clsGenericClass();

        Exception objErr = new Exception();
        objErr = Server.GetLastError().GetBaseException();

        objGen.InsertErrorLog(objErr.Message, "Error Caught in Application_Error event",
            Request.Url.ToString(), objErr.Source, "", DateTime.Now);

        Server.ClearError();
    }

Wednesday, February 6, 2013

SQL function for getting mid string


CREATE function [dbo].[MidString](@string varchar(100))
RETURNS varchar(100)
as
begin
Declare @strtloc int
Declare @endloc int
declare @result varchar(50)
set @strtloc = charindex('|',@string)+1
set @endloc = charindex('|',substring(@string,@strtloc,len(@string)))-1
if @endloc = -1
begin
set @endloc=len(@string)
end
set @result=substring(@string,@strtloc,@endloc)
return @result
end