Click here to Skip to main content
15,902,299 members
Articles / Web Development / ASP.NET
Article

Shopping Cart using C#.NET, Web Forms and SQL Server

Rate me:
Please Sign up or sign in to vote.
4.41/5 (62 votes)
20 Apr 20041 min read 692.1K   36.2K   153   164
Shopping cart using C#.NET, Web Forms and SQL Server.

Introduction

This application is a Shopping Cart where users can select items and place an order. I have added the features of login, and adding new users if user does not exist. Validations are performed wherever needed like email format validation, zipcode etc.

Fig. 1

Image 1

Database: For the purpose, I have used the NorthWind database and SQL Server.

The two main tables used are:

  1. Products table
  2. Order Details table.

I have used two classes:

C#
public class CartRow
{
    public string id;
    public string name;
    public string price;
    public string items;
};
public class Cart
{
    public System.Collections.ArrayList list = new ArrayList(20);
};

The two main web-forms are Main.aspx and CheckOut.aspx. Main.aspx contains a grid showing all items present in the products table along with the price per unit and the quantity per unit. Fig 1 shows the Main.aspx page, where user can select items from the products grid (left). As he selects an item, it is added to his cart and the item is displayed in the right panel. The total price is displayed in the label above. As the user adds more items to his cart, the recalculated price is shown. Upon clicking the clear cart button, the cart gets empty.

If the user now wants to finalize the order and presses the CheckOut button, he is redirected to the Login.aspx page (Fig 2). I have set the default username as “user” for the sample and password is “u”.

Fig 2.

Image 2

And finally, the user is asked to enter the Credit Card number, billing PIN code and his email address. It does the client side validations and then confirms the order placed by sending a mail to the user as shown in (Fig 3).

And the order is finalized. For more advanced shopping cart, this information plus the item information has to be stored in some database.

Fig 3

Image 3

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralDatabase Pin
ali1dc5-Jul-08 11:09
ali1dc5-Jul-08 11:09 
AnswerRe: Database Pin
mghanim9-Jul-08 17:59
mghanim9-Jul-08 17:59 
QuestionVisual web developper 2008 Pin
casper_mc22-Jun-08 7:41
casper_mc22-Jun-08 7:41 
GeneralNo database Pin
Francis Belmin18-May-08 22:33
Francis Belmin18-May-08 22:33 
Generalquestion Pin
nithydurai22-Apr-08 23:51
nithydurai22-Apr-08 23:51 
GeneralNo database in the sample Pin
cyn822-Apr-08 4:23
cyn822-Apr-08 4:23 
QuestionCan u gimme da solution? Pin
NYSMITH14-Mar-08 6:57
NYSMITH14-Mar-08 6:57 
GeneralSQL Server Error Pin
Member 477061117-Feb-08 1:23
Member 477061117-Feb-08 1:23 
An error has occurred while establishing a connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Data.SqlClient.SqlException: An error has occurred while establishing a connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)

Source Error:


Line 57: }
Line 58:
Line 59: sqlDataAdapter1.Fill(dsProduct1);
Line 60: DataGridProduct.DataBind();
Line 61: if (!IsPostBack)


Source File: c:\Shopping\Main.aspx.cs Line: 59

Stack Trace:


[SqlException (0x80131904): An error has occurred while establishing a connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)]
System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) +173
System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj) +199
System.Data.SqlClient.TdsParser.Connect(ServerInfo serverInfo, SqlInternalConnectionTds connHandler, Boolean ignoreSniOpenTimeout, Int64 timerExpire, Boolean encrypt, Boolean trustServerCert, Boolean integratedSecurity, SqlConnection owningObject) +348
System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, Boolean ignoreSniOpenTimeout, Int64 timerExpire, SqlConnection owningObject) +160
System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(String host, String newPassword, Boolean redirectedUserInstance, SqlConnection owningObject, SqlConnectionString connectionOptions, Int64 timerStart) +396
System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(SqlConnection owningObject, SqlConnectionString connectionOptions, String newPassword, Boolean redirectedUserInstance) +184
System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, Object providerInfo, String newPassword, SqlConnection owningObject, Boolean redirectedUserInstance) +196
System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection) +502
System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnection owningConnection, DbConnectionPool pool, DbConnectionOptions options) +28
System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject) +429
System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject) +70
System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection owningObject) +512
System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection) +85
System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory) +89
System.Data.SqlClient.SqlConnection.Open() +159
System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) +118
System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) +139
System.Data.Common.DbDataAdapter.Fill(DataSet dataSet) +82
Shopping.WebForm1.Page_Load(Object sender, EventArgs e) in c:\Shopping\Main.aspx.cs:59
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +13
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +43
System.Web.UI.Control.OnLoad(EventArgs e) +80
System.Web.UI.Control.LoadRecursive() +49
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3750


Could you please help me?

My email address is sahlone@hotmail.com
GeneralRe: SQL Server Error [modified] Pin
wsamuel29-Feb-08 21:26
wsamuel29-Feb-08 21:26 
Generalxin chao cac ban Pin
tutk1_phochome4-Jul-07 18:02
tutk1_phochome4-Jul-07 18:02 
GeneralRe: xin chao cac ban Pin
thanhducdn23-Sep-07 22:50
thanhducdn23-Sep-07 22:50 
GeneralAbout shopping Cart Pin
Member 33411835-Feb-07 5:10
Member 33411835-Feb-07 5:10 
GeneralRe: About shopping Cart Pin
lukyfaxy6-Jul-08 21:18
lukyfaxy6-Jul-08 21:18 
Questionadding extra details to each item Pin
GoFast12430-Oct-06 19:20
GoFast12430-Oct-06 19:20 
GeneralDo u have a 2.0 version of this cart Pin
Milton Karimbekallil8-Aug-06 2:03
Milton Karimbekallil8-Aug-06 2:03 
GeneralSQL Script - Creare Tables Pin
GreenWays2-Jul-06 5:13
GreenWays2-Jul-06 5:13 
GeneralGetCart Pin
htmlhenry3-Mar-06 6:34
htmlhenry3-Mar-06 6:34 
Questionthis code is not working ?? Pin
mrsalikahmed31-Jan-06 21:37
mrsalikahmed31-Jan-06 21:37 
Generalwhether to use datatable or arraylist or hashtable Pin
patilana9-Jan-06 1:21
patilana9-Jan-06 1:21 
AnswerUmer ! Use a DataTable Pin
Muhammad Umer Iqbal11-Jan-06 21:42
Muhammad Umer Iqbal11-Jan-06 21:42 
GeneralHelp SQL Error Pin
drumboy196722-Nov-05 13:25
drumboy196722-Nov-05 13:25 
GeneralRe: Help SQL Error Pin
drumboy196722-Nov-05 13:45
drumboy196722-Nov-05 13:45 
QuestionRe: Help SQL Error Pin
shewTos4-Jun-07 23:22
shewTos4-Jun-07 23:22 
GeneralRe: Help SQL Error Pin
patilana9-Jan-06 1:13
patilana9-Jan-06 1:13 
GeneralGood tutorials Pin
sanchayan_rohan16-Oct-05 23:48
sanchayan_rohan16-Oct-05 23:48 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.