473,396 Members | 1,799 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Not taking cookie and adding data

I am working with a shopping cart (I am suing a book). At this point I
am trying to add the cartID, the productID, quantity and time. At the
same time it is supposed to add a cookie. When I click the add to cart
button it gives me a postback but does not enter data in the database
or add the cookie. I have tried to work with permissions. Since it is
on my local machine I have added permission to everything I can think
of. Here is the code. I would love some help.

One thing I have considered is that my example is using a button in a
datalist while I am in a datagrid. Can that be an issue?

The button is in a template column of the datagrid. Here is the code
behind.

Private Sub datagrid1_ItemCommand(ByVal source As Object, ByVal e As
System.Web.UI.WebControls.DataGridCommandEventArgs ) Handles
datagrid1.ItemCommand
'in the command arguement of ther button that was clicked
'in the datagrid contains the productID
Dim intProductID As String = e.CommandArgument
'add the productto the shopping cart
ShoppingCart.AddProduct(intProductID)
End Sub

It is referring to a class called ShoppingCart.addproduct which is the
following

Public Shared Function AddProduct(ByVal intProductID As String)
' Create the connection object
Dim connection As New SqlConnection(connectionString)
' Create and initialize the command object
Dim command As New SqlCommand("AddProductToCart", connection)
command.CommandType = CommandType.StoredProcedure
' Add an input parameter and supply a value for it
command.Parameters.Add("@CartID", SqlDbType.Char, 36)
command.Parameters("@CartID").Value = shoppingCartID
' Add an input parameter and supply a value for it
command.Parameters.Add("@intProductID", SqlDbType.Int)
command.Parameters("@intProductID").Value = intProductID
' Open the connection, execute the command, and close the
connection
Try
connection.Open()
command.ExecuteNonQuery()
Finally
connection.Close()
End Try
End Function
I am also trying to take a cookie at the same time. It is not working
at all.

Here is the cookie code.

Private Shared ReadOnly Property shoppingCartID()
Get
Dim context As HttpContext = HttpContext.Current

' If the JokePoint_CartID cookie doesn't exit
' on client machine we create it with a new GUID
If context.Request.Cookies("doughboys_cartID") Is Nothing
Then
' Generate a new GUID
Dim CartID As Guid = Guid.NewGuid()
' Create the cookie and set its value
Dim cookie As New HttpCookie("doughboys_cartID",
CartID.ToString)
' Current Date
Dim currentDate As DateTime = DateTime.Now()
' Set the time span to 10 days
Dim ts As New TimeSpan(10, 0, 0, 0)
' Expiration Date
Dim expirationDate As DateTime = currentDate.Add(ts)
' Set the Expiration Date to the cookie
cookie.Expires = expirationDate
' Set the cookie on client's browser
context.Response.Cookies.Add(cookie)
' return the Cart ID
Return CartID.ToString()
Else
' return the value stored in JokePoint_CartID
Return
context.Request.Cookies("doughboys_CartID").Value
End If
End Get
End Property

Mar 15 '06 #1
0 1096

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

18
by: Paul | last post by:
I link to a web site from an Excel spreadsheet. The page i link to is getCookie.asp which sets a cookie then returns back some html which opens a new window, to the same site but a different page...
14
by: Alec S. | last post by:
Hi, I'm using JavaScript and Cookies for some customization in a web page. There may be several values in the cookie with names that are not known at runtime. I need a way of deleting them. ...
1
by: RCHENG | last post by:
Hi guys, I am pretty new to network programming with c#, and is having problem using cookie with HTTPWEBREQUEST object. My question involves sending a request with cookie. What I am trying to do...
3
by: Ben Amada | last post by:
Every time a user visits a particular page, I'm using the code below to add a cookie that expires in 1 day. My question is, a user may visit this page a few times within one day. Before adding...
3
by: Wysiwyg | last post by:
After a server created cookie is processed on the client I want it removed, cleared, or expired in the javascript block but have been unable to do this. If I set a cookie value in the server code...
0
by: Laura K | last post by:
I am working with a shopping cart (I am suing a book). At this point I am trying to add the cartID, the productID, quantity and time. At the same time it is supposed to add a cookie. When I...
4
by: D. | last post by:
Hi, I defined some cookies in order to pass values between pages in my application. The problem is that when i request them with: cookie = Request.Cookies("mycookie") x = cookie.Value (suppose...
1
by: flutetones | last post by:
http://67.189.52.24/~metafusionserver/public_html/training.php Here is a link to my server. I have an issue that doen't make sense. What's hapening is this . . . What's going right . . .
2
by: fran7 | last post by:
Hi, I have this very nice link tracker script that works a treat. The only thing is it doesnt restrict repeat clicking. Is there a simple method to add a cookie feature to this so that people...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.