Saturday, 26 September 2015

Difference Between Char and Varchar in SQL Server

Below list is major difference between Char[n] and varchar[n] Datatype in Sql Server;

Type
char[n]
Varchar[n]
Storage Type
Char is fixed length of datatype.
 If you declare variable with 20 character length. Like Char(20), 
it takes 20 bytes regardless storing 1 or 20 character.
varchar is fixed length of datatype. If you declare variable with 20 character length. Like varchhar(20), it takes number of bytes as defined.
Storage Example
DECLARE @Name Char(20) = 'Bob'
 SELECT DATALENGTH(@Name) as Result


Result
-----------
20

DECLARE @Name VarChar(20) = 'Bob'
 SELECT DATALENGTH(@Name) as Result

Result
-----------
3
Performance
If your content is fixed size than Char datatype has good to use.
It is performing better than char if variable datatype.
Which should Use
 Data can have Unicode characters.
Data doesn’t have any Unicode characters.



Difference Between NVarchar and Varchar in SQL Server

Below list is major difference between Varchar[n] and NVarchar[n] Datatype in Sql Server;


Type
nVarchar[n]
Varchar[n]
Storage Type
It store both Non Unicode and Unicode data e.g. it store the Hindi, Chinese etc.  Language.

e.g.
DECLARE @Name AS VARCHAR(50) =短发

  SELECT @Name
It store the Non Unicode character.

e.g.
DECLARE @Name AS VARCHAR(50) =‘Bob’
SELECT
 @Name
Maximum Storage
It store maximum 4000 Unicode and Non-Unicode character.
It store maximum  8000  Non-Unicode character
Bytes Required for Each character
It store 1 Byte per Character.
It store 2 byte per character either it is Unicode or non Unicode.
Which should Use
 Data can have Unicode characters.
Data doesn’t have any Unicode characters.


Friday, 24 July 2015

Rendering Helpers in MVC

MVC provides many Rendering helpers and you can use it based on your need ;
Please see on below links for more details about it.


1. @HTML.Action and @HTML.ActionLink

2. URL Helpers

3. @HTML.Partial and @HTML.RenderPartial

4. @HTML.Action and @HTML.RenderAction in MVC

@HTML.Action and @HTML.RenderAction in MVC

Action and renderAction are similar to Partial & RenderPartial helpers.
Partial helps to view render a portion of view model using view markup in separate file.

Action execute a separate controller action and display the result. Action offer more flexible and reuse because the controller action can build a different model and make use of a separate controller context.

Difference in action and renderaction is the render action writes directly to the response.

URL Helper in MVC

The URL Helper is Similar to HTML Action Link & Route Link Helpers. http://www.getmscode.com/2015/07/htmlactionlink-mvc.html

But instead of returning HTML, they build URLs & return URLs as string.

Three Helpers for URL.
Ø  Content
Ø  Action
Ø  Route URL


Action URL is same link Action link, But doesn’t return an anchor Tag.
@URL.Action(“Browse”,”Store”, new { ID = 100}, null)

HTML.ActionLink MVC

The actionlink method renders a hyperlink (anchor tag) to another controller action.

e.g When linking to action in the same controller used to render the currentview, you can simply specify the action name;

@html.ActionLink(“Link Text”,”Action”);

This produces the flowing markup.

<a href=“/home/anotheraction”>LinkText</a>

You can specify the action
@Html.ActionLink(“Link Text”, “Index”,”Open”);


Sunday, 19 July 2015

Difference between @Html.Partial and @Html.RenderPartial

Generally we are getting confuse to use @Html.Partial and @Html.RenderPartial.

You can see below for Difference between @Html.Partial and  @Html.RenderPartial it help you to use it

1.       Return Type :  Partial Return Type is MVCHtml String; whereas RenderPartial  return type is void.

2.       Implementing  : Calling of partial Need to  call as:
@HTML.Partial(“PartialViewName”);
Render Partail Will call as;
{HTML.RenderPartial(“PartialViewName”)}
We enclose it like this because return type is Void;

Tuesday, 16 June 2015

open resx file in xml format

If you are opening the resourse file, it will open it in tabular format, with key, value and descriptions.

Like below screen.If you will edit the resorse file in this format it shows changes in many place even you added one value.

Sunday, 14 June 2015

itextsharp html to pdf


1.  Before starting the code for conversting the HTML to PDF using ITextSharp you need to download the ITextsharp Dll and placed it into the Bin folder. You can get the ItextSharp Dll from below path;


2.  Now you want to generate the PDF, by clicking any of the button in your page, You have to place the below code on your C# file and  there it will pass the HTML content to the Export method where it is using the ItextSharp methods for converting the HTML to PDF..

protected void btnGeneratePDF_Click(object sender, EventArgs e)
        {
            StringWriter sw = new StringWriter();
            HtmlTextWriter hw = new HtmlTextWriter(sw);
            this.Page.RenderControl(hw);
            //   string redirectUrl = HttpContext.Current.Request.Url.AbsoluteUri;
          

Wednesday, 27 May 2015

read xml attribute value c#

Due to get some Values from HTML or for XML there we need to Read XML Attributes Values from given string in C#.

There is the sample code below; which is using System.Xml.Linq.
which will help you to over come this problem. and read the XML attribute value through c#


Suppose you have the XML attributes as below; There we are finding the description from Given attributes.

string str = @"<label description='My Button Text' languagecode='5001' />";