Search This Blog

Saturday 22 August 2015

Difference between Convert.ToString () and .ToString () or Convert.ToString vs ToString c# or Convert.ToString vs .toString()

Step 1:- Explanation 

1.  .ToString () doesn't handle the null value. 
2.  Convert.ToString() handles null value.

Step 2:-  .ToString()
 

using System;

namespace ToString
{
    public class Program
    {
        static void Main(string[] args)
        {
            Object obj = null;

            string value1 = obj.ToString(); //Error
            Console.WriteLine(value1);

            Console.ReadLine();
        }
    }
}

Step 3:-  Output




Step 4:-  Convert.ToString() 

using System;

namespace ConvertDotToString
{
    public class Program
    {
        static void Main(string[] args)
        {
            Object obj = null;

            string value1 = Convert.ToString(obj); //Return Null Or Blank
            Console.WriteLine(value1);

            Console.ReadLine();
        }
    }
}

Step 5:- Output


 

State Management In Asp.net

State Management In Asp.net

View state

Control state

Hidden fields

Cookies

Query strings

Application state

Session state

Profile Properties

1. Client-Based State Management Options

View state

Control state

Hidden fields

Cookies

Query strings

2. Server-Based State Management Options

Application state

Session state

Profile Properties

What is the difference between out and ref parameter? or Out vs Ref parameter

Step 1 :- Explanation

ref parameter must first be initialized before being passed from the calling function to the called function. but an out parameter need not be initialized. 

The called function must set the value of 
out variable before control returns to calling function.

Step 2:- Complete Code

using System;

namespace Ref_vs_Out
{
    public class Program
    {
        public void RefMethod(ref int value)
        {
            value++;
        }

        public void OutMethod(out int value)
        {
            value = 50;
        }

        static void Main(string[] args)
        {
            Program p = new Program();

            int refValue = 50;
            p.RefMethod(ref refValue);
            Console.WriteLine("Ref value - " + refValue);

            int outvalue;
            p.OutMethod(out outvalue);
            Console.WriteLine("Out value - " + outvalue);


            Console.ReadLine();
        }
    }
}

Step 3:- Output




Note :- 

You cannot differentiate the method overloading only with ref and out keyword.


        public void Method(ref int value)
        {
            value++;
        }

        public void Method(out int value)
        {
            value = 50;
        }

Following error occurred.

Cannot define overloaded method 'Method' because it differs from another method only on ref and out.


Wednesday 19 August 2015

Insert Hindi text in sql server or Save Hindi, Marathi Content in Sql Server database or How to store Hindi data in sql server 2005 or Data saving in Hindi in sql server 2008

Step 1:- Create Temp table

CREATE TABLE #PlanetOrderList
(
       ID INT IDENTITY,
       HindiName VARCHAR(50),
       EnglishName VARCHAR(50),
       RomanName VARCHAR(50),
)

Step 2:- Insert record in table

INSERT INTO #PlanetOrderList(HindiName,EnglishName,RomanName)
VALUES ('सूर्य','Sun','Surya'),
       ('बुध','Mercury','Budha'),
       ('शुक्र','Venus','Sukra'),
       ('पृथ्वी','Earth','Prithvi'),
       ('मंगल','Mars','Mangal'),
       ('बृहस्पति','Jupitar','Brahspati'),
       ('शनि','Saturn','Shani'),
       ('अरुण','Uranus','Arun'),
       ('वरूण','Neptune','Varun'),
       ('यम','Pluto','Yam')

Step 3:- Result




Note:-

Here HindiName column record showing?????


How to solve?


Step 4:- Change the data type of the column (HindiName) to NVARCHAR (50or NTEXT Instead of VARCHAR (50)

CREATE TABLE #PlanetOrderList
(
       ID INT IDENTITY,
       HindiName NVARCHAR(50),
       EnglishName VARCHAR(50),
       RomanName VARCHAR(50),
)

Step 5:- Append "N" before the string name

INSERT INTO #PlanetOrderList(HindiName,EnglishName,RomanName)
VALUES (N'सूर्य','Sun','Surya'),
       (N'बुध','Mercury','Budha'),
       (N'शुक्र','Venus','Sukra'),
       (N'पृथ्वी','Earth','Prithvi'),
       (N'मंगल','Mars','Mangal'),
       (N'बृहस्पति','Jupitar','Brahspati'),
       (N'शनि','Saturn','Shani'),
       (N'अरुण','Uranus','Arun'),
       (N'वरूण','Neptune','Varun'),
       (N'यम','Pluto','Yam')

Step 6:- Result


Friday 14 August 2015

Creating linked server to MySQL from SQL server or Setup SQL Server Linked Server to MySQL

DNS: - Domain Name System

Step 1:- Download Connector/ODBC 


Step 2:- GO TO

Start => Control Panel => System & Security => Administrative Tools => Data Sources (ODBC)

Step 3: GO TO

System DNS => Click on Add Button => Select MySQL ODBC 5.3 Unicode Driver from List => Click on Finish Button => Fill Details => Click on Test Button => Click on OK Button => Click on OK Button

Step 4:- Step by Step

Start


Control Panel


System & Security


Administrative Tools => Click on Data Sources (ODBC)


Select System DNS => Click on Add Button



Select MySQL ODBC 5.3 Unicode Driver from List => Click on Finish Button



Fill Details



Click on Test Button => Click on OK Button to close popup => Click on OK Button



Click on OK Button




Linked Server

Step 1:- GO TO

MS SQL Server => Expand Server Objects => Expand Linked Servers => Right on Linked servers => Click on New Linked Server... => Fill Left Side General Tab details => Fill Left Side Security Tab details => Click on OK Button

Step 2:- GO TO

Expand Providers => Right Click MSDASQL => Select Properties => Select following Checkbox => Click OK Button

Step 3:- Step by Step

MS SQL Server




Expand Server Objects


Expand Linked Servers



Right on Linked servers



Click on New Linked Server...




Fill Left Side General Tab details




Fill Left Side Security Tab details => Click on OK Button





Expand Providers


Right Click MSDASQL => Select Properties





Select following Checkbox => Click OK Button





QUERY




Note:-

1.         Your DNS Name and Linked Server Name must be same.
2.         Step is based on local server due to which, while creating the DSN password field is empty. You can use MY SQL password if you given.
3.         After establishing a linked connection use the OPENQUERY to get data or query.
  
Example: - OPENQUERY ( linked_server ,'query' )


SELECT * FROM OPENQUERY(SFA_MYSQL,'SELECT * FROM INFORMATION_SCHEMA.TABLES LIMIT 10')