Sunday, June 21, 2009

CRM 4.0 Calling Web Service

public static CrmService GetCrmService(string orgName, string server)
{

CrmAuthenticationToken token = new CrmAuthenticationToken();
token.AuthenticationType = 0;
token.OrganizationName = orgName;

CrmService service = new CrmService();

service.Credentials = System.Net.CredentialCache.DefaultCredentials;
service.CrmAuthenticationTokenValue = token;
service.Url = string.Format("http://{0}/mscrmservices/2007/crmservice.asmx", server);
return service;

}

Friday, April 24, 2009

How to ouput the results to File (SQL Server)

Either do Control + shift + F
or
Go to Query -> Result To -> Select "Output to file"
Now when you will run the query, system will ask for the file to save the results.

Friday, April 17, 2009

difference between the console.read and console.readlline

Console.Readline reads the entire line of data.
Console.Read reads only one character at a time.
Console.Write will writes to the screen and leaves the cursor until the user hits enter.
Console.WriteLine writes to the screen and will perform a carriage return and line-feed.

Wednesday, April 15, 2009

How to create the proxy class from WSDL

Open Start-> visual Studio 2008 -> Tools -> Command prompt

browse to the desired directory

and type

wsdl www.wsdlurl.com/wsdl

and a file will be created

Tuesday, April 14, 2009

How to use Foreach in c# Arrays

string[] WeeKdays = new string[7];

WeeKdays[0] = Sunday";
WeeKdays[1] = "Monday";
WeeKdays[2] = "Tuesday";
WeeKdays[3] = "Wednesday";
WeeKdays[4] = "Thursday";
WeeKdays[5] = "Friday";
WeeKdays[6] = "Saturday";

foreach (object row in Weekdays)
{
Response.Write(row + " , ");
}

Thursday, April 9, 2009

Loop through each row in dataset

foreach (DataRow row in dsDataset.Tables[0].Rows)
{
Console.writeline(row["ColmnName1"].tostring();
Console.writeline(row["ColmnName2"].tostring();
.
.
.
}

Date Compare in C#

Visual Basic

Dim t1 As DateTime
Dim t2 As DateTime
Dim returnValue As Integer

returnValue = DateTime.Compare(t1, t2)


C#
public static int Compare(
DateTime t1,
DateTime t2
)

Parameters
t1
Type: System..::.DateTime
The first DateTime.

t2
Type: System..::.DateTime
The second DateTime.

Return Value
Type: System..::.Int32
A signed number indicating the relative values of t1 and t2.

Value Type Condition

Less than zero t1 is earlier than t2.
Zero t1 is the same as t2.
Greater than zero t1 is later than t2.

Example:
C#

DateTime t1 = new DateTime(100);
DateTime t2 = new DateTime(20);

if (DateTime.Compare(t1, t2) > 0) Console.WriteLine("t1 > t2");
if (DateTime.Compare(t1, t2) == 0) Console.WriteLine("t1 == t2");
if (DateTime.Compare(t1, t2) < 0) Console.WriteLine("t1 < t2");