Knowledge Transfer

Monday, December 29, 2008

Difference between StringBuilder and String.Concat method in C#.Net

Hi DotNetGems,

StringBuilder Namespace : System.Text.StringBuilder (Mutable)
String Namespace : System.String (Imutable)

Now Both String.Concat(),Fromat(),join() Methods are Concating the string values to another string value but why C#.Net Introduce the StringBuilder Class???????????
.
.
.
Difference between StringBuilder and String?
Difference between mutable and Immutable?

How String Concatenation String Builder Append affects performance

Most of us have used String concatenation in our projects, Have we ever given a thought to what goes on behind while concatenating the strings?

There is a major flaw in using string concatenation as against the String builders append concerning performance only.
Except for performance and memory management both are same and give us the same desired output.

How they work
Lets take a look at how the things work when we concatenate strings

lets take a case where we are concatenating 2 strings and assigning the output to a 1st string

outputString += secondString;

In the above case, each instance of the string is created and assigned hence

in total we will have 3 instances of the strings!! Surprised?? well thats how strings concatenation works

It will create a new string outputString,with both old outputString and secondString

String objects in .net are immutable. Once the string has been created, the value can’t be changed. When you type
outputString = outputString + secondString;
you actually discard the old outputString and create a new string object containing the result of the concatenation. When repeated several times, you end up constructing many temporary string objects.

now just imagine the case where you have n number of strings you have to concatenate how many string objects will be created wont that be a waste of time ??? Creating a string object assigning it some value then again creating a string object and so on …..

Imagine the impact on the performance of the application!!!!

Now lets see how String builder works

Using a string builder you will have


System.Text.StringBuilder outputString = new System.Text.StringBuilder();

outputString.Append(secondString);

StringBuilder, is a mutable string hence in this case we just have 1 instance of outputString and the second string is appended into that existing instance
no other instance is created hence the process is efficient and fast.

Note :- The point to remember here is that using StringBuilder for a concatenation of 2-3 strings doesnt make a significant difference in the performance but when you have numerous strings then the usage of StringBuilder has a big positive Impact on the performance

Labels: , , , , , ,

Happy New Year - 2009

Hi DotNetGems,
Wish You a Happy New Year -2009



All The Best,
Uday.Adidham

Labels: , , , , , , , , , , , , , ,

Monday, December 22, 2008

Happy holidays,Happy Chirstmas,Happy New Year,2009

Hi DotNetGems,



Happy New Year and Happy Holidays

Uday.Adidham

Labels: , , , , , ,

Condolences to PV Narashimha Rao (Prime minister 21-JUN-1991 to 16 may 1996)

Sorry DotNetGems...

Sorry for upload irelevent stuff to my Bolg.But i am happy about to upload good stuff for our former 12th Primeminister Mr.P.V.Narashimaha Rao(18th JUN 1921 to 23 DEC 2004).i hope we all appriciate this post and give comment about this.Please remember our Indian Real Heros.Today Mr.PV s 4th Death Anniversary..please Condoleance to PV.




Johar PV Narshimha Rao.

Labels: , , ,

Sunday, December 21, 2008

ASP.Net Page LifeCycle ,LifeCycle


Here i am explain the asp.net page lifecycle.Please Click on the images for Enlarge....






Happy Coding
Uday.Adidham

Labels: , , ,

Thursday, December 18, 2008

How to Access Network Files using asp.net?

Here I am Showing How to Access Network Files and Folder using asp.net

When we Develop web application to dealing with Files and folders, at that time our web server is not quite capable to manage files and folder, so in this scenario we can use two different server to manage application properly, so we need Web Server to host our web application and File Server to manage files and folder.

To implement that scenario In Web application, there are so many ways to do that. Here I am showing it using Synchronize the IUSR account between the two machines. We can do using Asp.net Impersonate. We can implement asp.net impersonate in different way, mean by programmatically or using web.config file

For More Stuff please Click this link
http://www.codeproject.com/KB/aspnet/UNC__Access_Network_file.aspx

Happy Coding
Uday.Adidham

Labels: , , , , , , ,

Wednesday, December 17, 2008

Using Params Keyword in C#.Net

Sometimes we may require a variable number of arguments to be passed to a function. For example we may require a sum function which calculates the total of the numbers passed to it no matter how many numbers are passed.

In C# we can use the Params keyword and pass variable no of arguments to a function. It's much like using ParamArray in VisualBasic language. The syntax of params arguments is:
params datatype[] argument name

Note that the argument passed using params argument should be an single dimension array also it should be the last argument in the argument list for the function.

The params parmeter can then be accessed as an normal array.

Example

class ParamsTest
{
static void Main()
{
System.Console.WriteLine(sum(2,3,4)); // Three Arguments Passed
System.Console.WriteLine(sum(10,20,30,40,50,60));//Six Arguments
}
static int sum(params int[] num)
{
int tot=0;
foreach(int i in num)
{
tot=tot+i;
}
return tot;
}
}

Happy coding,
Uday.Adidham

Labels: , , , , ,

Using Params Keyword in C#.Net

Sometimes we may require a variable number of arguments to be passed to a function. For example we may require a sum function which calculates the total of the numbers passed to it no matter how many numbers are passed.

In C# we can use the Params keyword and pass variable no of arguments to a function. It's much like using ParamArray in VisualBasic language. The syntax of params arguments is:
params datatype[] argument name

Note that the argument passed using params argument should be an single dimension array also it should be the last argument in the argument list for the function.

The params parmeter can then be accessed as an normal array.

Example

class ParamsTest
{
static void Main()
{
System.Console.WriteLine(sum(2,3,4)); // Three Arguments Passed
System.Console.WriteLine(sum(10,20,30,40,50,60));//Six Arguments
}
static int sum(params int[] num)
{
int tot=0;
foreach(int i in num)
{
tot=tot+i;
}
return tot;
}
}

Happy coding,
Uday.Adidham

Labels: , , , , ,

Good website for all asp.net,c#.net Codes and articles,Faq's and interview questions?

The below site describes the all the good concepts for asp.net,c#.net,vb.net and sql server and comarsion about the .net and java technologies .tips and tracks avilable...

Click Here

Happy Coding,
Uday.Adidham

How to disable the Cookies in one web pages with in the project? and session in asp.net ?

i have posted two sample IMP questions for cookies and sessions

How to disable the Cookies in one web pages with in the project?
Using request.Cookies.discard

How to disable the session in one web page with in the project?

session state management in ASP.NET requires overhead. So, if a particular page will not be accessing the Session object, developers can set the EnableSessionState attribute of the Page directive for that page to False. If a particular page will be accessing the Session object and not altering the value of the session, then set the EnableSessionState attribute of the Page directive for that page to Readonly. Session state can be disabled for an entire site by setting the mode attribute of the sessionState element to Off in the Web.config.

Happy Coding,
Uday.adidham

Labels: , , ,

Monday, December 15, 2008

what is Response.redirect(URL,Bollean value(True/false)) .

We are very frequently using the response.redirect(url) in our asp.net application for redirecting the pages from one page to another page.With in response.redirect(url,[true/false]) one more paramets in that function that is Bollean value parameters. why i am using that Boolean value in response.redirect() method.i think all of know about the Response.redirect() and server.tranfer and server.execute() methods.i skip that introducation and Prons and cons and bla ..bla...

::now i am discuss the resposne.redirect(url,[true/false])::

Since the advent of Server.Transfer(url) I've used Response.Redirect(url) less and less, but for those times when you want the client to know of the location from where information will be retrieved it's still your best option. So you use it, never expecting that the simple call you've used for years with ASP would throw an exception in ASP.NET.

The ThreadAbortException is thrown when you make a call to Response.Redirect(url) because the system aborts processing of the current web page thread after it sends the redirect to the response stream. Response.Redirect(url) actually makes a call to Response.End() internally, and it's Response.End() that calls Thread.Abort() which bubbles up the stack to end the thread. Under rare circumstances the call to Response.End() actually doesn't call Thread.Abort(), but instead calls HttpApplication.CompleteRequest(). (See this Microsoft Support article for details and a hint at the solution.)

Though one could argue the logic behind throwing this exception in the first place, there are a couple of ways to get around this.

The try-catch block

try
{
Response.Redirect(url);
}
catch (ThreadAbortException ex)
{
}
The first solution, and the most common one found in an internet search, is to simply wrap the call to Response.Redirect in a try-catch block. Although it appears to work I don't like it for two reasons:

Processing an exception can be costly and messy
The rest of the page and event chain continues to execute
Since the exception is caught the page continues to execute through it's event chain which takes up unnecessary CPU resources and potentially sends unwanted data to the client (which will be ignored since the client received a redirect).

A better way.

Since the real culprit is the call to Thread.Abort(), how can we Redirect the page without making that call? We would have to tell the client to redirect without calling Response.End() of course, and it turns out that there is an overload method of Response.Redirect() that will do exactly that.

Response.Redirect(string url, bool endResponse);
In this overload the second parameter tells the system whether to make the internal call to Response.End() or not. When this parameter is false the client is sent the redirect url, but the internal call to Response.End is skipped. This completely avoids the code that would throw the exception, but the cost is that this thread doesn't stop executing the Application events! Thankfully we can solve that problem also by duplicating the step that Response.End() takes under those rare circumstances, namely calling the HttpApplication.CompleteRequest() method.

HttpApplication.CompleteRequest() sets a variable that causes the thread to skip past most of the events in the HttpApplication event pipeline and go straight to the final event, named HttpApplication.EventEndRequest. This gracefully ends execution of the thread with a minumum of server resources.

Alain Renon pointed out to me on Gabriel Lozano-Morán's blog that the page still sends the rendered HTML to the client. He's absolutely right. In fact, Page events still execute and the Page still processes postback events too. The event pipeline that I am talking about short circuiting with the call to HttpApplication.CompleteRequest() is not the Page event chain but the Application event chain. The Application event chain currently consists of the following events as of .NET 2.0:

ValidatePathExecutionStep
UrlMappingsExecutionStep
EventBeginRequest
EventAuthenticateRequest
EventDefaultAuthentication
EventPostAuthenticateRequest
EventAuthorizeRequest
EventPostAuthorizeRequest
EventResolveRequestCache
EventPostResolveRequestCache
MapHandlerExecutionStep
EventPostMapRequestHandler
EventAcquireRequestState
EventPostAcquireRequestState
EventPreRequestHandlerExecute
CallHandlerExecutionStep
EventPostRequestHandlerExecute
EventReleaseRequestState
EventPostReleaseRequestState
CallFilterExecutionStep
EventUpdateRequestCache
EventPostUpdateRequestCache
EventEndRequest

I've bolded CallHandlerExecutionStep because that is the step where all of the Page events take place. If you make a call to HttpApplication.CompleteRequest() from a Page event such as Page_Load then the Page events still process to completion, but all the Application events between CallHandlerExecutionStep and EventEndRequest are skipped and the thread ends gracefully.

One could argue that it doesn't matter so much that the page is still rendered since the client ignores it anyway, but Alain is correct that it does render, and that's not as efficient as we could make it. Also, if you have any PostBack processing (such as OnCommand Page event handlers) those will process and you may not want that either, but never fear there is an easy solution to both of those problems as well.

PostBack and Render Solutions? Overrides.

The idea is to create a class level variable that flags if the Page should terminate and then check the variable prior to processing your events or rendering your page. This flag should be set after the call to HttpApplication.CompleteRequest(). You can place the check for this value in every PostBack event or rendering block but that can be tedious and prone to errors, so I would recommend just overriding the RaisePostBackEvent and Render methods as in the code sample below:

private bool m_bIsTerminating = false;

protected void Page_Load(object sender, EventArgs e)
{
if (WeNeedToRedirect == true)
{
Response.Redirect(url, false);
HttpContext.Current.ApplicationInstance.CompleteRequest();
m_bIsTerminating = true;
// remember to end the method here if
// there is more code in it
return;
}
}

protected override void RaisePostBackEvent(IPostBackEventHandler sourceControl, string eventArgument)
{
if (m_bIsTerminating == false)
base.RaisePostBackEvent(sourceControl, eventArgument);
}

protected override void Render(HtmlTextWriter writer)
{
if (m_bIsTerminating == false)

base.Render(writer);
}
The Final Analysis

Initially I had recommended that you should simply replace all of your calls to Response.Redirect(url) with the Response.Redirect(url, false) and CompleteRequest() calls, but if you want to avoid postback processing and html rendering you'll need to add the overrides as well. From my recent in depth analysis of the code I can see that the most efficient way to redirect and end processing is to use the Response.Redirect(url) method and let the thread be aborted all the way up the stack, but if this exception is causing you grief as it does in many circumstances then the solution here is the next best thing.

It should also be noted that the Server.Transfer() method suffers from the same issue since it calls Response.End() internally. The good news is that it can be solved in the same way by using the solution above and replacing the call to Response.Redirect() with Server.Execute().

Happy coding!

Labels: , , ,

how to display and retrive the two tables data into two datagirds in ado.net

For example i have one storedprocedure(name : Sp_myprocedure) then

::sp_myprocedure::

Create procedure sp_myprocedure as
begin
select * from table1
select * from table2
end

Then how to call this stored procedure and display the two tables(table1,table2) data into two data grids.

ok....Understood...if understood u got answer ..otherwise

i am leaving some code to readers like data conception,data adapter and dataset initlizations...

take two data grids ,
dg1.datasource = ds.tables[0]
dg2.datasource = ds.tables[1]

Happy ADO.NET,
Uday.Adidham

This article explains to fill a AutoComplete Textbox from the data fetched from database in AJAX

Everyone knows about the AutoComplete Textbox. It is an ASP.NET AJAX extender that can be attached to any TextBox control. When the user types some letters in the Textbox, a popup panel will come to action and displayed the related words. So that the user can choose exact word from the popup panel. Here I tried to explain how this AutoComplete fetches data from the database through a Webservice.

Open Microsoft Visual Studio, click on New Website. Then choose ASP.NET Ajax Enabled Website and change the location to point your http://localhost/AutoComplete folder. Obviously, Default.aspx is added to your solution explorer.

Now drag and drop a Textbox from your Toolbox. Then drag and drop a ScriptManager and AutoCompleteExtender to your Default.aspx page. Then add a webservice to your project as WebService.asmx. First thing you have to do is to add the ScriptService reference to the webserive as follows.
[System.Web.Script.Services.ScriptService]


Now, write a webmethod ‘GetCountryInfo’ to fetch the data from the country table as follows

[WebMethod]
public string[] GetCountryInfo(string prefixText)
{
int count = 10;
string sql = "Select * from Country Where Country_Name like @prefixText";
SqlDataAdapter da = new SqlDataAdapter(sql,”Your Connection String Comes Here”));
da.SelectCommand.Parameters.Add("@prefixText", SqlDbType.VarChar, 50).Value = prefixText+ "%";
DataTable dt = new DataTable();
da.Fill(dt);
string[] items = new string[dt.Rows.Count];
int i = 0;
foreach (DataRow dr in dt.Rows)
{
items.SetValue(dr["Country_Name"].ToString(),i);
i++;
}
return items;
}


The above webmethod takes prefixText as argument, sends it to the query to fetch only the related words that starts with the prefixText values. Then it returns the result as an array of strings.

Next, in the Default.aspx page, set the AutoCompleteExtender’s TargetControlID property to the TextBox Id. Now you can see a new Extenders Tab is added in the Textbox’s Property window. Set ServicePath as WebService.asmx, ServiceMethod as GetCountryInfo and MinimimPrefixLength as 1.




Now, its time to run the project. Select the Default.aspx and click on View in Browser. You can see the excellent application starts to run. Type your country’s first letter. See all the countries starts with that letter will appear in the popup.

Resource From Click Here Part-1
Click Here Part-2

Happy AJAX,
Uday.Adidham

Labels: , , ,

Thursday, December 11, 2008

How can i include both C# and vb.net classes in same

1)How can i include both C# and vb.net classes in same
solution?

It is possible,In app-Code folder create sub folders
named VB,CS(as you like) and clreate .vb class files in the
folder named VB and .cs class files in the CS folder.
Step 2:
Go to web.config file and mention the following

in web.config file ....

< compilation debug="false" >
< codesubdirectories >
< add directoryname="VB" >
< add directoryname="CS" >



-------------------
HappyCoding
Uday

Labels: , , ,

How can i include both C# and vb.net classes in same

1)How can i include both C# and vb.net classes in same
solution?

It is possible,In app-Code folder create sub folders
named VB,CS(as you like) and clreate .vb class files in the
folder named VB and .cs class files in the CS folder.
Step 2:
Go to web.config file and mention the following







-------------------

Labels: , , ,

How to Build ConnectionString at Run-Time/Dynamically in ADO.Net

SqlConnectionStringBuilder is a class that helps to create and manage connection strings at run-time. You can change any connection string setting through your code whenever and wherever you want.

Sample Code for SqlConnectionStringBuilder:

SqlConnectionStringBuilder cnbuilder = new SqlConnectionStringBuilder();

cnbuilder.DataSource = "MyServerName";
cnbuilder.ConnectTimeout = 1000;
cnbuilder.IntegratedSecurity = false;
cnbuilder.UserID = "sa";
cnbuilder.Password = "MyDBServerPassword";

Response.Write(cnbuilder.ConnectionString);


The above block of code, create a connectionstring based on the values you passed to the DataSource, UserId and Password fields. You can directly use this SqlConnectionStringBuilder object to open a connection as follows


SqlConnection cn = new SqlConnection(cnbuilder.ConnectionString);
cn.Open();

This link is for Creating Class file fire DataAccess Leayer not For Above Stuff.
Data Access layer


Labels: , , , , , , , , ,

How to Build ConnectionString at Run-Time/Dynamically in ADO.Net

SqlConnectionStringBuilder is a class that helps to create and manage connection strings at run-time. You can change any connection string setting through your code whenever and wherever you want.

Sample Code for SqlConnectionStringBuilder:

SqlConnectionStringBuilder cnbuilder = new SqlConnectionStringBuilder();

cnbuilder.DataSource = "MyServerName";
cnbuilder.ConnectTimeout = 1000;
cnbuilder.IntegratedSecurity = false;
cnbuilder.UserID = "sa";
cnbuilder.Password = "MyDBServerPassword";

Response.Write(cnbuilder.ConnectionString);


The above block of code, create a connectionstring based on the values you passed to the DataSource, UserId and Password fields. You can directly use this SqlConnectionStringBuilder object to open a connection as follows


SqlConnection cn = new SqlConnection(cnbuilder.ConnectionString);
cn.Open();


Labels: , , , , , , , , ,

Wednesday, December 10, 2008

Good site for all .Net interview Questions in C3.net,vb.,net,sql server

These all topics avialbe in the below link..this is good site for all C#.net and asp.net people...

.NET Framework
Algorithms and Data Structures
C# Programming
Debugging
Design Patterns
Input / Output
Network and Internet
Performance
Programming Concepts
SQL Server
Visual Studio
Windows Forms
Latest Articles
Visual Studio Go To Definition Command
C# Iterators
Adapter Design Pattern
Adding Assemblies to the Global Assembly Cache
Checking Scroll Lock Status
SQL Server Indexes Part 2
Generating Temporary Files
C# Friend Assemblies
Visual Studio 2008 Transparent Intellisense
C# Static Classes

Please Click here Please Click Here

Happy Research

These all topics avialbe in the below link..this is good site for all C#.net and asp.net people...

.NET Framework
Algorithms and Data Structures
C# Programming
Debugging
Design Patterns
Input / Output
Network and Internet
Performance
Programming Concepts
SQL Server
Visual Studio
Windows Forms
Latest Articles
Visual Studio Go To Definition Command
C# Iterators
Adapter Design Pattern
Adding Assemblies to the Global Assembly Cache
Checking Scroll Lock Status
SQL Server Indexes Part 2
Generating Temporary Files
C# Friend Assemblies
Visual Studio 2008 Transparent Intellisense
C# Static Classes

Please Click here Please Click Here

Happy Research

Tuesday, December 9, 2008

Interview Questions on asp.net,c#.net,webservices and ajax nad xml For all companies

Hi Dotnet Developers and Fresher

i have place the link for .net applications Interviews Questions and FAQS about all the concepts in asp.net,c#.Net,vb.net,web services,windows services,remotinmg and ajax and XML and etc...etc....

please click here for finding the FAQ's
Please Click Here

Happy Interview,

Labels: , , , , ,

Multilevel Nested Master/Detail Data Display Using GridView

This article presents how the GridView control can be nested to show master/detail relationships for multilevel hierarchal data. In this article, I have implemented it for three levels, and it can be implemented for n levels quite easily, by maintaining the information about the edit index of the parent GridView controls.

This article provides a simple, easy, and clean solution for displaying data with multilevel master/detail relationships. This article also shows how the GridView can be used effectively by using its template fields, and how controls inside template fields are accessed and bound. More importantly, you will realize the power of GridView's edit mode, and learn how it can be used to do things other than editing; evading from its default usage!!

parent and Child relation in Gridview in asp.net 2.0

Please Click here about more stuff Multilevel Nested Master/Detail Data Display Using GridView

Happy Coding,

Labels: , ,

Friday, December 5, 2008

i3-soft Interview Questions,Hyderabad,Ameerpet

Hi,Recently in I3-Soft Interview questions,Ameerpet,Hyderabad

Sqlserver
---------
* - How to create Clustured index explicitly
* - Avoiding to create clustured index in table..wt conditions are u used
* - Diff b/w Stored procedures and UDF
* - Describe Trigger and types
* - Cursors
* - describe Clustred and Nonclustered indexes
* - Sqlserver view
* - locking in sqlserver
* - Is we call UDF in application If yes how?
ASP.Net
--------
Event bubbling
view state
caching -sqlcache dependency
Passing dynamic values to another page
C#
----------
Abstract and Interface
Value type and Reference type and examples
Is class extends multiple interfaces
Boxing and Unboxing
use of Virtual keyword
Assemblies

Happy Coding

Labels: , , ,

Thursday, December 4, 2008

Dot Net Certification Details: Microsoft MCTS(70-528, 70-536), MCP , MCPD (70-547), MCSE, MVP AND MCSD

Microsoft certification exams are very confusing. Every aspirant has to search a lot to demystified the best exams etc. Here in next few paragraph i am going to demystify Microsoft Certfication in .net.
In .net Microsoft offers following categories

* MCTS
* MCPD
* MCSD
* MCP
* MVP

MCTS - The Microsoft Certified Technology Specialist. This is the fresh exam and do not require any previous exams to clear it. So a new developer can start from this exam.

Following are the specialization and exams under those

.NET Framework 2.0 Web Applications

one has to pass the following examinations:

* Exam 70–536: TS: Microsoft .NET Framework 2.0 - Application Development Foundation

* Exam 70–528: TS: Microsoft .NET Framework 2.0 - Web-Based Client Development

.NET Framework 2.0 Windows Applications

one has to pass the following examinations:

* Exam 70–536: TS: Microsoft .NET Framework 2.0 - Application Development Foundation

* Exam 70-526: TS: Microsoft .NET Framework 2.0 – Windows-Based Client Development

.NET Framework 2.0 Distributed Applications
one has to pass the following examinations:

* Exam 70–536: TS: Microsoft .NET Framework 2.0 - Application Development Foundation

* Exam 70–529: TS: Microsoft .NET Framework 2.0 – Distributed Application Development
--------------------------------------------------------------------------------------------

MCPD -Microsoft Certified Professional Developer

this is next step to the MCTS, so to clear it you firstly need to have MCTS in your tally
Folloings are .NET 2.0, Visual Studio 2005 and SQL Server 2005.

Professional Developer: Web Developer
* Prerequisite: MCTS: .NET Framework 2.0 Web Applications
* Exam 70-547: PRO: Designing and Developing Web Applications by Using the Microsoft .NET Framework

Professional Developer: Windows Developer
Following examinations:

* Prerequisite: MCTS: .NET Framework 2.0 Windows Applications
* Exam 70–548: PRO: Designing and Developing Windows Applications by Using the Microsoft .NET Framework

Professional Developer: Enterprise Applications Developer
Following examinations:

* Prerequisite: MCTS: .NET Framework 2.0 Web Applications
* Prerequisite: MCTS: .NET Framework 2.0 Windows Applications
* Prerequisite: MCTS: .NET Framework 2.0 Distributed Applications
* Exam 70–549: PRO: Designing and Developing Enterprise Applications by Using the Microsoft .NET Framework

MCP Microsoft Certified Professional. Person having any ms certification is called MCP

MVP Microsoft Most Valuable Professional. This does not require any exam. It is related with how you contributed in the microsoft communties or any site that promote ms technologies. You could be MVP of any of the these c#,asp.net,web services,word,excel,

For more Information Click this link Click Here

Happy All the best,

Labels: , , , , , , , , ,