.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
Sharon Maxwell
Post New Web Links

New code block suggestion

Posted By:      Posted Date: May 22, 2011    Points: 0   Category :Windows Application
 

In my latest project all the calls to Data Access Layer (or any other layer for that matter) return ArrayList of errors. in one of the functions i have about 25 calls to data layer, because i'm saving a huge object that has to create/update/delete from about 15 tables in the DB. Since i don't want to continue execution if one call returns any error my code looks like this:

if (errorList.Count == 0)

{

    //massage data

    errorList = dataLayer.Save1(object1);

}

if (errorList.Count == 0)

{

    errorList = dataLayer.Save2(object2);

}

etc...

this creates extra 25 if conditions. So i thought there should be a better way.

So my suggestion is to introduce a new code block similar to 'try' 'catch', but 'try' 'catch' only watches for exceptions; I suggest a custom block (like 'watch' 'found' or something of that nature) where you can specify the condition that you are looking for. If condition is found -> execute found block. So instead of the code above my code could look like:

watch (errorList.Count > 0)

{

    errorList = dataLayer.Save1(object1);

    errorList = dataLayer.Save2(object2);

    etc...

found




View Complete Post


More Related Resource Links

RSS implementation code - need suggestion

  

Please suggest what is the best approach of coding for RSS implementation,

 

Implementation 1:

a) Add custom handler in web.config for .rss type

b) Create a handler class (RSSHandler.cs) in APP_Code

c) Create a Sample.rss file

d) Browse Sample.rss in browser

 Technical Solution:Utility Classes:I)                   

How do I get column values in Sharepoint designer so I can use them as a variable in code block?

  
The code below is in my EditForm.aspx and it works but instead of it outputting "This is just a test!" I need get a number that is stored in a column named Phone Number that has 5555555555 stored in it and have the line that says TD2.innerHTML = "This is just a test!"; ouput what ever number is stored in the Phone Number column. Here is the code that is in my EditForm.aspx <script type="text/javascript">function DisplayItemID(){       var TD1 = document.createElement("TD");       TD1.className = "ms-formlabel";       TD1.innerHTML = "<h3 class='ms-standardheader'>Test</h3>";       var TD2 = document.createElement("TD");       TD2.className = "ms-formbody";       TD2.innerHTML = "This is just a test!";       var IdRow = document.createElement("TR");       IdRow.appendChild(TD1);       IdRow.appendChild(TD2);       var ItemBody = GetSelectedElement(document.getElementById("idAttachmentsRow"),"TABLE").getElementsByTagName("TBODY")[0]; 

Changing Properties/Attributes of a Webpart in inline code block - Error 'System.Web.UI.WebControl

  
I'm trying this code below, but gettting error: System.Web.UI.WebControls.WebParts.WebPart' does not contain a definition for 'FilterValue1' I need to change the value of the FilterValue1 properties of a content Query WebPart with title = Applicant Files. Thanks in Advance!
protected override void OnLoad(EventArgs e) {  base.OnLoad(e); SPSecurity.RunWithElevatedPrivileges(delegate() { using (SPSite SiteCollection = new SPSite("https://somesite/")) { SPWeb myWeb = SiteCollection.OpenWeb(); myWeb.AllowUnsafeUpdates = true; Microsoft.SharePoint.WebPartPages.SPLimitedWebPartManager mgr = null; mgr = myWeb.GetLimitedWebPartManager("default.aspx",System.Web.UI.WebControls.WebParts.PersonalizationScope.Shared); foreach (System.Web.UI.WebControls.WebParts.WebPart myWebPart in mgr.WebParts) { if (myWebPart.Title == "Applicant Files") { myWebPart.FilterValue1 = "/13"; mgr.SaveChanges(myWebPart); break; } } } }); }

Embedded code block question

  
Hello,i know it's a very basic problem but i can't use an asp.net code block the way i want.I have used those before but it seems i encountered a case i haven't seen before.<asp:SqlDataSource ID="SqlDataSourcetblCategoriesPourListe" runat="server" ConnectionString="<%$ ConnectionStrings:BottinConnectionString %>" ProviderName="System.Data.SqlClient" SelectCommand="SELECT label from mytable WHERE (HOrder = @HOrder)))"> <SelectParameters> <asp:QueryStringParameter DefaultValue="<% (int)GetDefaultValue()%>" Name="HOrder" QueryStringField="HOrder" /> </SelectParameters> </asp:SqlDataSource>Whenever i run this, i get an exception:Syntax error converting the nvarchar value '<% (int)GetDefaultValue()%>' to a column of data type int.How can i avoid this ?I am not doing it in the code behind because i use nested gridviews and sqldatasources.  Can't access nested sqldatasources from code behind, as far as i know.

Login SQL Server with Dynamic Code and block SSMS remote connection

  

Dear all,

- Can we configure SQL Server login integrated using Dynamic Code (TOKEN) ?

As far i know , we can use Dynamic code / Token with Login Windows, but i dont know about Token/Dynamic Code with SQL Server login.

- and can we block SSMS Remote connection, so we cannot connect using SSMS /Query analyzer to the server. The only way is local connection.

thanks in advance

Our Environments :
-SQL Server 2K8EE integrated with LUna HSM & RSA

-Win Server 2k8EE

 


Regards, Mathias.Arya

Code Optimized Web Development Profile (VS 2010 and .NET 4.0 Series)

  
When you first run VS 2010 it prompts you to select an IDE profile to use. The profile you select will configure how tool windows are displayed/docked in the IDE by default and set the default keyboard shortcuts. You can then customize any of these settings by using the Tools->Options menu within the IDE and then override/change them. You can also later reset your profile and pick a different one by choosing the Tools->Import and Export Settings menu command.

Free Code Snippets - ASP.NET

  
You Can Find Useful ASP.NET Related Posts on the above link.

Free Code Snippets - C#

  
Free C# Code Snippets

call JavaScript - jQuery code from ASP.NET Server-Side

  
jQuery got so close to me lately that I can see myself adding the scripts to my project almost unconsciously. The thing is, jQuery is very useful for me, in almost all situations and it has been a do or die enhancement for all my project since I first put my hands on it.

Of course while using it, you encounter few situations which need a bit of research to solve, mostly when you are trying to combine it with some other technologies like: UpdatePanels and ASP.NET Ajax. For instance there are many situations when I would like to run some jQuery magic based on some decision that I make on the server side.

call JavaScript - jQuery code from ASP.NET Server-Side

  
jQuery got so close to me lately that I can see myself adding the scripts to my project almost unconsciously. The thing is, jQuery is very useful for me, in almost all situations and it has been a do or die enhancement for all my project since I first put my hands on it.

Of course while using it, you encounter few situations which need a bit of research to solve, mostly when you are trying to combine it with some other technologies like: UpdatePanels and ASP.NET Ajax. For instance there are many situations when I would like to run some jQuery magic based on some decision that I make on the server side

MVC architecture in ASP.Net using C# and Microsoft Data Access Application block

  
The Model-View-Controller (MVC) pattern separates the modeling of the domain, the presentation, and the actions based on user input into three separate classes [Burbeck92]:

Model. The model manages the behavior and data of the application domain, responds to requests for information about its state (usually from the view), and responds to instructions to change state (usually from the controller).

View. The view manages the display of information.

Controller. The controller interprets the mouse and keyboard inputs from the user, informing the model and/or the view to change as appropriate.

Microsoft StyleCop: Source Code Analyzer for C#

  
StyleCop is similar in many ways to Microsoft Code Analysis (specifically FxCop), but there are some important distinctions. FxCop performs its analysis on compiled binaries, while StyleCop analyzes the source code directly. For this reason, FxCop focuses more on the design of the code, while StyleCop focuses on layout, readability and documentation. Most of that information is stripped away during the compilation process, and thus cannot be analyzed by FxCop.

Code spelling checker extension for visual studio 2010

  
Building a spelling checker for source code as an extension for visual studio 2010.

C# and XML Source Code Documentation

  
Through many years of enterprise level software development and consulting, I became critically aware of the importance of good source code documentation, and several years ago when I began working with the first release of Visual Studio .NET beta 1 and found C# provided built-in support for inline XML code documentation, I was thrilled.

Bar Code Scanners with the .NET Compact Framework

  
Summary: Learn how to make your applications use bar code scanners in a generic way-ndependent of the specific bar code scanners that are used on different devices. Using the design patterns Façade and Factory, the implementation not only supports multiple bar code scanners, but it also makes it easy to add support for other bar code scanners. After a brief discussion about bar code scanners and the bar code scanner pattern, a download code sample, written in C#, demonstrates the use of the pattern and technologies.

PrinterCE for .NetCF - Code Samples

  
1)Example:Hello World
2)Example:Form Test
3)Example:DrawTextFlow
4)Example:TextColumns
5)Example: Bar Code Test
6)Example:Text Wheel
7)Example:Image Rotation
8)Example:Line Fun

.net code converter

  
For coverting your programming langugae to another languge the below site is very help full

http://www.developerfusion.com/tools/convert/vb-to-csharp/
Categories: 
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend