Thursday, 14 June 2012

C# Null Coalescing Operator


The C# Null Coalescing Operator (??)  is a binary operator that simplifies checking for null values. 

Eg:
X??y

While executing code, if x evaluates to null, y is returned as the value. Also remember that the
 null coalescing operator (??) is right-associative which means it is evaluated from right to left. So if you have an expression of the form x ?? y ?? z, this expression is evaluated as x?? (y?? z).


Eg:
int? a = 0;
int b = a ?? 0;

Answer b=0

int? a = 6;
int b = a ?? 0;

Answer b=6

While executing code, if a evaluates to null, b is returned as the value. 



Get Datasource,Username,Password from Connection String


string conString = "SERVER=localhost;DATABASE=db;UID=root;PASSWORD=test;";
                SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder(conString);
                string user = builder.UserID;
                string pass = builder.Password;
                string datasource = builder.DataSource;

Add New column with default value in existing table


  System.Data.DataColumn newColumn = new System.Data.DataColumn("columnName", typeof(System.String));
newColumn.DefaultValue = "Your DropDownList value";
table.Columns.Add(newColumn);

Monday, 11 June 2012

The maximum message size quota for incoming messages (65536) has been exceeded. To increase the quota, use the MaxReceivedMessageSize property on the appropriate binding element.

I got this error
"The maximum message size quota for incoming messages (65536) has been exceeded. To increase the quota, use the MaxReceivedMessageSize property on the appropriate binding element."
when i received data from the server.
for this problem i set MaxReceivedMessageSize in my client side.


<wsHttpBinding>
    <binding name="test" closeTimeout="00:01:00" openTimeout="00:01:00"
     receiveTimeout="00:10:00" sendTimeout="00:01:00" bypassProxyOnLocal="false"
     transactionFlow="false" hostNameComparisonMode="StrongWildcard"
     maxBufferPoolSize="524288" maxReceivedMessageSize="2147483647" messageEncoding="Text"
     textEncoding="utf-8" useDefaultWebProxy="true" allowCookies="false">
(or)


WSHttpBinding binding = new WSHttpBinding();
            binding.MaxReceivedMessageSize = 2147483647;
            EndpointAddress endpointAddress = new EndpointAddress("http://localhost:59167/Service1.svc");
            ServiceReference1.Service1Client sc = new ServiceReference1.Service1Client(binding,endpointAddress);

Hope this helps.

Wednesday, 6 June 2012

short cut for show desktop

shortcut for show desktop - windows+D
Visual Studio
Ctrl-.[dot  Display options on smarttag menu.
                  Very useful for showing using/Imports options.

Ctrl+k Ctrl+D Format source code 


http://www.dofactory.com/ShortCutKeys/ShortCutKeys.aspx

ClientScript.RegisterStartupScript+ navigating to another page + while pressing back button alert


 ClientScript.RegisterStartupScript(this.GetType(), "script", "alert('hello !');__doPostBack('__Page', 'EmptyPostback');", true);


To avoid alert message using RegisterStartupScript  while click on browser back button.


When we register the startup script with the alert, immediately follow the alert statement with one which will refresh the page. This ensures that the startup script is removed from the page as soon as the OK is clicked, and if the user returns to the page the alert pop up does not reappear.