how to use shopping cart in asp.net

Posted by Shanky11 under ASP.NET on 9/19/2013 | Points: 10 | Views : 1358 | Status : [Member] | Replies : 18
i have created a website for ecommerce
in that website i need to add shopping facilities
now my problem is
there is add cart button
on every cart button value stored in database and again reload in cart griedview.
now problem is:-when i exit this application
it again show the previous added item
how can i delete this value from temporary table in sql(i m storing this value in sql )
is there any way to delte this added item whenver user exit the application




Responses

Posted by: Bandi on: 9/19/2013 [Member] [MVP] Platinum | Points: 25

Up
0
Down
Which table you are using. I mean to say that normal table or temporary table..
In this scenario better to use temp tables. for instance, #tableName
Temp tables will be dropped from DB whenever session is closed

Alternate is whenever session is closed update the table column with null value....



Mark This Response as Answer
--
Chandu
http://www.dotnetfunda.com/images/dnfmvp.gif

Shanky11, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Shanky11 on: 9/19/2013 [Member] Starter | Points: 25

Up
0
Down
normal sql table named temporder
how can
how can we delete temp table whenever session is closed.
please tell me the full scenario

Shanky11, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Bandi on: 9/19/2013 [Member] [MVP] Platinum | Points: 25

Up
0
Down
Hi Shanky,
While creating table itself precede table name with # symbol......
For example, TableName is temporder then use table name as #temporder

By default temp tables will be dropped automatically whenever the session/application is closed

Mark This Response as Answer
--
Chandu
http://www.dotnetfunda.com/images/dnfmvp.gif

Shanky11, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Shanky11 on: 9/19/2013 [Member] Starter | Points: 25

Up
0
Down
SqlCommand cmd = new SqlCommand("insert into #temporder(pname,pimage,price) values('" + name + "','" + imgname + "','" + price + "')", con);
temorder table is create bout how can i use insert and delete query
above is giving error invalid table name

Shanky11, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Bandi on: 9/19/2013 [Member] [MVP] Platinum | Points: 25

Up
0
Down
where do you created #temporder ?
Before that you should create the table....

CREATE TABLE #temporder (pname varchar(50), ,pimage varcahr(50), price dec(10,2))
insert into #temporder values('safsa', 'sfsafs', 323)

Mark This Response as Answer
--
Chandu
http://www.dotnetfunda.com/images/dnfmvp.gif

Shanky11, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Shanky11 on: 9/19/2013 [Member] Starter | Points: 25

Up
0
Down
i created table ##temporder in tempdb

Shanky11, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Shanky11 on: 9/19/2013 [Member] Starter | Points: 25

Up
0
Down
create table ##temporder
(

pid int identity primary key,pname nvarchar(100),pimage nvarchar(Max),price nvarchar(8)
)
its ok this table value is binding in griedview now i want whenever i close the webpage or app this table shoul be deleted

Shanky11, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Shanky11 on: 9/19/2013 [Member] Starter | Points: 25

Up
0
Down
i hav created table in tempdb
create table ##temporder
(

pid int identity primary key,pname nvarchar(100),pimage nvarchar(Max),price nvarchar(8)
)

Shanky11, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Bandi on: 9/19/2013 [Member] [MVP] Platinum | Points: 25

Up
0
Down
check the application once....
By default whenever DB connection is closed then automatically temp table will be deleted from memory....

There is difference between ##temporder and #temporder
#temporder is specific to session whereas ##temporder is specific to connection...

Check the app with #temporder




Mark This Response as Answer
--
Chandu
http://www.dotnetfunda.com/images/dnfmvp.gif

Shanky11, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Shanky11 on: 9/19/2013 [Member] Starter | Points: 25

Up
0
Down
if i am using #temporder
it is showing invalid object
when i tried to selct * from # tremporder in code behind page

Shanky11, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Shanky11 on: 9/19/2013 [Member] Starter | Points: 25

Up
0
Down
Invalid object name '#temporder'.
it is showing this error
public void loadgrid()
{

DataTable dt = new DataTable();
SqlCommand cmd = new SqlCommand("select * from #temporder", con1);
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(dt);
GridCart.DataSource = dt;
GridCart.DataBind();
Session.Abandon();
}
public void inserttemporder()
{

con1.Open();
SqlCommand cmd = new SqlCommand("insert into #temporder(pname,pimage,price) values('" + name + "','" + imgname + "','" + price + "')", con1);
cmd.ExecuteNonQuery();
con1.Close();
}
see the above code i will retrieve the data from table and agian insert it into temp table

Shanky11, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Bandi on: 9/19/2013 [Member] [MVP] Platinum | Points: 25

Up
0
Down
create table in the code behind only before trying to insert data....



Mark This Response as Answer
--
Chandu
http://www.dotnetfunda.com/images/dnfmvp.gif

Shanky11, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Shanky11 on: 9/19/2013 [Member] Starter | Points: 25

Up
0
Down
how can i create table in code behind please tell me

Shanky11, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Shanky11 on: 9/19/2013 [Member] Starter | Points: 25

Up
0
Down
i am creating table in sql by query by following way
CREATE TABLE #temporder(
pid int identity primary key,
pname nvarchar(50),
pimage nvarchar(Max),
price float
)

Shanky11, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Bandi on: 9/19/2013 [Member] [MVP] Platinum | Points: 25

Up
0
Down
means you are creating table in SQL Editor/SQL Server Management Studio/VS ?
through code only create the table before insert....

--Alternate approach is:
May be try with Datatable creation programmatically
http://www.c-sharpcorner.com/UploadFile/0524d6/create-table-programmatically-in-Asp-Net/


Mark This Response as Answer
--
Chandu
http://www.dotnetfunda.com/images/dnfmvp.gif

Shanky11, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Shanky11 on: 9/19/2013 [Member] Starter | Points: 25

Up
0
Down
ya i am creating table in sql management studio


Shanky11, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Bandi on: 9/19/2013 [Member] [MVP] Platinum | Points: 25

Up
0
Down
That is the reason you are getting invalid object name error...
#temp tables will be dropped whenever that SQL Editor is closed

Mark This Response as Answer
--
Chandu
http://www.dotnetfunda.com/images/dnfmvp.gif

Shanky11, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Bandi on: 9/19/2013 [Member] [MVP] Platinum | Points: 25

Up
0
Down
Refer this link for knowing when user closes web page...
Do a delete operation on page close event
http://www.codeproject.com/Articles/10771/Detect-browser-closing-through-clicks-on-the-X-but

NOTE: use Page unload event or follow this link
http://forums.asp.net/t/1124072.aspx

Mark This Response as Answer
--
Chandu
http://www.dotnetfunda.com/images/dnfmvp.gif

Shanky11, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response