Good Practice When Retrieving SQL Data?

Jan 19, 2011

I'm currently using the fantastic DorkNozzle 'framework' for building a very basic blog in .NET.My first "self-taught" script is as follows, and is for solely retrieving SQL results.

PHP Code:

<%@ Page Language="C#" MasterPageFile="~/Dorknozzle.master" AutoEventWireup="true" Title="Blog" %>
<%@ Import Namespace = "System.Data.SqlClient" %>
<script runat="server">[code]....

I should change to perhaps improve my coding style, without going down the MVC line just yet?

View 17 Replies


Similar Messages:

Is This Modified C# Singleton Pattern A Good Practice

Feb 9, 2010

I'm developing a blog application shared by non-profit organizations. I want each organization to be able to change their own blog settings. I have taken a singleton pattern (from BlogEngine.net) and modified it. (I understand that it is no longer a singleton pattern.) I have tested this approach and it seems to work fine in a development environment. Is this pattern a good practice? Are there issues, which may arise when this is placed in a production environment?

public class UserBlogSettings
{
private UserBlogSettings()
{
Load();
}
public static UserBlogSettings Instance
{
get
{
string cacheKey = "UserBlogSettings-" + HttpContext.Current.Session["userOrgName"].ToString();
object cacheItem = HttpRuntime.Cache[cacheKey] as UserBlogSettings;
if (cacheItem == null)
{
cacheItem = new UserBlogSettings();
HttpRuntime.Cache.Insert(cacheKey, cacheItem, null, DateTime.Now.AddMinutes(1),
Cache.NoSlidingExpiration);
}
return (UserBlogSettings) cacheItem;
}
}
}

(Portions of code were omitted for brevity.)

View 3 Replies

Good Practice To Avoid Using Session State In MVC?

Mar 7, 2011

It's not explicitly written somewhere but I felt so after reading few blogs on ASP.NET MVC. Just got curious and thought of asking it here.

UPDATE: I'm not asking about memory/storage/RAM concerns on server. For them, there is a solution to store session out of process. I know that. I'm curious that, are there any scenarios where we had to use Session in WebForms but we can avoid it now in MVC taking benefit of the nice structured way offered by MVC?

View 6 Replies

C# - Is It A Good Practice To Implement Logic In Properties

May 27, 2010

we use ASP.NET with C# and based on open source projects/articles I passed through, I found many properties were including a logic but when I did so the team-leader told me it's not good at all to place logic inside properties but to call the logic through methods...

View 6 Replies

Good Practice - Connection String In Web.config?

Jun 30, 2010

Whats the difference, if in my web.config i use. both works with my code. what is right way of diong it? keeping connection string?

[code]...

View 4 Replies

C# - Is It A Good Practice To Write HTML Using A StringBuilder In Codebehind

Mar 25, 2010

I'm interested to hear from other developers their opinion on an approach that I typically take. I have a web application, asp.net 2.0, c#.

What I usually do to write out drop downs, tables, input controls, etc. is in the code behind use StringBuilder and write out something like sb.Append("

I don't find myself using to many .net controls as I typically write out the html in the code behind. When I want to use jQuery or call JavaScript I just put that function call in my sb.Append tag like sb.Append("td...onblur='fnCallJS()'.

I've gotten pretty comfortable with this approach. For data access I use EntitySpaces.

I'm just kind of curious if this sort of approach is horribly wrong, ok depending on the context, good, time to learn 3.0, etc. I'm interested in learning and was just looking for some input.

Edit

After reading the comments here it sounds like I should take a look at MVC. I've not done that yet. The only hesitancy in doing so is that the existing project is just that, existing. There is a lot of code already done the way I explained and it is hard to imagine what would be involved in changing it, advantages of doing so, and just learning what that would take.

The other thing I'm taking away from the comments is that my code behind should really not include much of the sb.Append code, whereas now it is filled with it in numerous functions. To me it is not messy but that is because I know what each function does and can look at it and see, oh that writes out x, y, and z.

It's not uncommon for me to just have a div on the .aspx part and then build up the .innerHtml of that with the StringBuilder in the code behind.

View 7 Replies

C# - An ImageMap For A Navigation Menu Considered Good Practice?

Feb 2, 2010

Should I use an ImageMap to create a navigation menu?

View 1 Replies

Which Pattern Most Closely Matches Scenario Detailed And Is It Good Practice

Mar 6, 2011

I have seen a particular pattern a few times over the last few years. In the UI, each new record (e.g., new customers details) is stored on the form without saving to database. This clearly has been done so not clutter the database or cause unnecessary database hits.

While in the UI state, these objects are identified using a Guid. When these are a saved to the database, their associated Guids are not stored. Instead, they are assigned a database Int as their primary key.

The form can cope with a mixure of retrieved items from the database (using Int) as well as those that have not yet been committed (using Guid).

When inspecting the form (using Firebug) to see which key was used, we found a two part delimited combined key had been used. The first part is a guid (an empty guid if drawn from the database) and the second part is the integer (zero is stored if it is not drawn from the database). As one part of the combined key will always uniquely identify a record, it works rather well.

View 3 Replies

Does Anyone Know A Good Practice To Use When Developing For The System.directory Services Class

Jan 31, 2011

I'm trying to create a data access later using System.DirectoryServices. I'd like to use the MVC 2 framework and have all my views be mostly strongly-typed. Does anyone know any good way to this?

For example I started creating a Group Entity:

public class Group
{
public string DistinguishedName { get; set; }
public string GroupName { get; set; }
}

And an abstract interface:

public interface IGroupRepository
{
List<Group> Groups { get; }
}

I am confused about developing the GroupRepository using the system.directory services. Connecting to a SQL database is easy there are examples everywhere but I have no been able to find any using the System.directory sevices in conjunction with a class using MVC. Has anyone tried to do something like this?

View 1 Replies

C# - Good Practice To Perform Direct Database Access In The Code-behind Of Webpage?

Jun 7, 2010

I am an experienced developer but I am new to web application development. Now I am in charge of developing a new web application and I could really use some input from experienced web developers out there.

I'd like to understand exactly what experienced web developers do in the code-behind pages. At first I thought it was best to have a rule that all the database access and business logic should be performed in classes external to the code-behind pages. My thought was that only logic necessary for the web form would be performed in the code-behind. I still think that all the business logic should be performed in other classes but I'm beginning to think it would be alright if the code-behind had access to the database to query it directly rather than having to call other classes to receive a dataset or collection back.

View 2 Replies

Forms Data Controls ::looking For A Good Way To Have Sum Row Of A Gridview

May 3, 2010

I know we can write code at the footer to get the sum of rows value.

However it is really a lot of work and all Gridviews I have have different columns etc.
I almost go crazy now if I need to add all these.

Is there a quick way to get this done ? I am so disappointed in .Net4 Gridview this is not enhanced.

View 3 Replies

Vb - What Is The Best Practice For Ouputting Data From A Collection On A Webpage

Apr 20, 2010

I've ported a page from classic ASP to ASP.net. Part of what happens in this page is that a collection of custom types is generated and then displayed via Response.Write() commands. I'd like to get the business logic separated out into a code behind file (and maybe move this all into a user control), but I can't seem to figure out how I'd actually display the collection once it's been generated. I want to specify a master page here, too, so the code can't stay inline. Here's a very stripped down version of the current code:

[code]....

View 3 Replies

C# - Best Practice For Uploading Excel Data In SQL Server Using .NET

Mar 4, 2010

I am looking for best practice for uploading excel data in Sql server 2000 database through asp.net web application. Excel data will be predefined Format with almost 42 columns and out of 42 10 fields are mandatory and rest are conditional mandatory. i.e. if data exists it should be in defined format. I also need to validate for special character, length, specified format and so on.After validating, i need to store valid data into sql server table and provide export to excel functionality for invalid data for exporting in same excel format with indicator to identity the invalid cells.

View 3 Replies

Forms Data Controls :: What Is The Best Practice To Search

Aug 3, 2010

I have more than 10000000 records, I want to search particuar records,What is the best way and practice to search.

View 5 Replies

Looking For Good Method To Handle Data Invalidation Or Timeout?

May 10, 2010

I understand the need for a function like DB_Get_Cached("sql string") that hashes the SQL in order to perform a lookup in memcached for the existence of the data.

function DB_Get_Cached(string SQL)
data = memcache_get_data(md5(SQL))
if (!data)
return DB_Get(SQL)
end if
end function


What is a good method to expand this to handle data invalidation or timeout?

I'm thinking in terms of product pages in an e-commerce site, or user details in their profile.

View 2 Replies

ADO.NET :: Is Filter Expression Is Good For Large Amount Of Data

Feb 20, 2011

I have above 4,00,000 records. I have more searching options.

Is filter expression is good for better performance or I will build the query with WHERE condition?

Which process is better for searching in large amount of data?

View 1 Replies

SQL Server :: Best Practice To Save And Retrive Data Using Properties

Mar 2, 2011

I have created one class as Employee.

Then i created properties, as below

[code]....

and same properties to be used while retriving data from sql server.

View 4 Replies

C# - Best Practice For Inserting/updating Data In Multiple Tables At Once?

Feb 11, 2011

So I have two tables in my database, Contacts and Addresses:

Contacts : ContactID | AddressID | FirstName | LastName

Addresses: AddressID | Address1 | Address2 | City | State | Zipcode

I have a page where you can add a contact. It contains all the information for a contact and an address for a contact. Here's my code for when you submit the form:

[code]...

Now my main concern is that the address is added successfully, but then an error occurs when I try to save the contact, leaving the address in the database with no contact.

What's the best practice here for rolling back any changes if an error occurs?

View 4 Replies

Entity Framework - .NET EntityFramework 4 Data Context / What Is The Best Practice

Oct 2, 2010

I'm working on a project which is using EntityFramework 4 and I am using the entity objects as my business objects. I ran into an issue recently where I had a context declared in a using statement in a user control. The method the statement was in returned an entity object which got used in another control. So I had to detach the entity then attach it to the new context in the other control. I would like to avoid this if possible. What I'm thinking is I would like to declare a context in the master page and then pass that to any page/usercontrol that needs it so they are all using the same context and I don't have to write all these using statements.

My questions are these:

1) is it a bad practice to declare a context on Pre_Init/Page_Load and then dispose of it on Page_Unload?

2) if it is what is the best practice for handling them?

3) if I do go the route of declaring the context in the master page what is the best way to pass that to the pages/usercontrols?

View 1 Replies

WCF / ASMX :: Best Practice For Blocking Requests Until Data Is Cached?

Mar 13, 2011

I have a RESTful webservice. This webservice builds some information (which can take upwards of a couple seconds) and caches the contents.

This works well; however, suppose that many of the same requests come in at about the same time. In our current scenario, each request will build the content before caching. This is obviously not desired as it uses CPU time that could be better served elsewhere. What I would like to do is to suspend/block requests to the same url/cachekey until the content has been built and cached, at which time those other requests will be unblocked and simply fetch the content from cache.

I am not sure the best way. The following are options I have thought about:

Use string.Intern on that cache key and lock. Problem is that this could cause a deadlock if that string is used elsewhere. Use a ConcurrentDictionary and WaitHandle objects to allow other request to lookup in the dictionary if a request is being processed and then "wait" for the request to finish. This would at least give me a timeout capability but I am concerned with the performance of creating many wait handles.

View 2 Replies

Forms Data Controls :: Finding Good Sample Code

Feb 20, 2011

do u also any good code projects for developing inbox functionality.

just that users could communicate with each other It does not need to as high level using System.net.mail

Just when the user clicks on Inbox shuld fetch data from db. and send and save to draft, navigation, querystrings, grid view did my own but just want to see other examples.

View 1 Replies

AJAX :: Looking For A Good Guide To The Asynchronous Loading Of Data From The Database?

Mar 24, 2010

Looking for a good guide to the asynchronous loading of data from the database after 2 seconds from the page_load.I need a method that does not burden the operation site!

View 18 Replies

Security :: Best Practice For Storing Users Data In Signup Form?

May 21, 2010

Just wanted to know what is the best pratice for storing new fields data when an user sign up ?

Also...

1- Is there a way to make the login controls use the same database than my website database?

2- It is okay to use the Membership and Role API to manager users from an user interface (without the ASP.NET Web configuration tool) ?

View 9 Replies

Forms Data Controls :: Best Practice For Gridview Creation/Maintenance?

Oct 7, 2010

I have been tasked with producing a web application for a new client. What they're looking for requires a Gridview with slave Detailsview within an Update Panel.

I produced this, including the Gridview in markup, as follows:[Code]....
[Code]....

However, although it works, it's been requested that I move most of this to code behind (for easier maintenance), which is causing me a few headaches.

What is the correct option here, since I see many potential methods?

Should I create an instance of the Gridview and Update Panel in markup, then define all events and columns in code behind? Create a new Gridview entirely in code behind and place it within the Update Panel? Create both in code behind?

View 8 Replies

Best Practice: General Asmx Data Loading Web-method Or Multi Web-methods

Apr 3, 2011

which is better approach from performance point of view, is it better to use one web-service method to load data by passing Database Table name and keys or is it better to use separate method for each database table! knowing that i'm using .net asmx through ajax requests.it's obvious that one method is better from OO perspective since it have one function type 'data loading' but what about performance? does IIS affected by that or not? also is it better to make multi web-services 'asmx files' or just one!

View 3 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved