asp.net


Data table + session = Shopping cart


GM everybody
i'm finding some issues in the implementation of my shopping cart
The query works but it doesn't store information in session.
Will i fix the query or the problem is the session ?
Here the code :
Dim constr As String = ConfigurationManager.ConnectionStrings("!aCommerce-ConnectionString!").ConnectionString
' Query SQL
Using cmd As New SqlCommand("SELECT Id,NomeProdotto, PrezzoProdotto, Quantità FROM aProdotti WHERE ID='" + Request.QueryString("ID").ToString + "' OR ID='" + Request.QueryString("ID").ToString + "'")
Using sda As New SqlDataAdapter(cmd)
Dim dt As New DataTable()
Session("dt") = dt
sda.Fill(dt)
GridView1.DataSource = dt
GridView1.DataBind()
End Using
End Using
End Using
change you code to below
Dim constr As String = ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString
Dim con As New SqlConnection()
con.ConnectionString = constr
con.Open()
' Query SQL
Using cmd As New SqlCommand("SELECT Id,PromoCode as NomeProdotto,PromoCodeMessage as PrezzoProdotto, PromoCodeLimit as Quantità FROM EventPromocodetbl WHERE ID=" & Request.QueryString("ID").ToString & "", con)
Using sda As New SqlDataAdapter(cmd)
Dim dt As New DataTable()
sda.Fill(dt)
Dim SessionDt As New DataTable()
SessionDt = Session("dt")
If Not SessionDt Is Nothing Then
If (dt.Rows.Count > 0) Then
Dim dr As DataRow
dr = SessionDt.NewRow()
dr("Id") = dt.Rows(0)("Id").ToString()
dr("NomeProdotto") = dt.Rows(0)("NomeProdotto").ToString
dr("PrezzoProdotto") = dt.Rows(0)("PrezzoProdotto").ToString
dr("Quantità") = dt.Rows(0)("Quantità").ToString
SessionDt.Rows.Add(dr)
End If
Session("dt") = SessionDt
GridView1.DataSource = SessionDt
GridView1.DataBind()
Else
Session("dt") = dt
GridView1.DataSource = dt
GridView1.DataBind()
End If
End Using
End Using
Problem is you are assigning blank DatatTable to session and then you are filling that DataTable using DataAdapter fill method that is issue.

Related Links

.net api connection error
Deny access to asp.net app to unauthenticated users
Unable to send selected items in database
ASP.NET MVC Windows Authenticate with extending properties
WSAT Manage User Accounts and Roles
CUDA/OpenCL acceleration in asp.net core application
Server cannot set status after HTTP headers have been sent from Elmah
Dynamic Routing doesn't work on IIS in simple Asp.Net WebForm Application
issue with datetime jquery asp.net mvc
How To Bind A DataTable To Multiple Chart Series
I'm trying to get drop down list with search in it
Make Cursor Pointer Busy
IISExpress ArgumentOutOfRangeException - Parameter name: site
Upload image in ASP.NET MVC 5 EF6
asp.net server redirect causing Not Found [CFN #0005]
Asp.Net Core / IdentityServer Complex Authorization

Categories

HOME
asterisk
stata
macros
pyspark
fortran
wifi
abc
android-ndk
azure-database-mysql
django-middleware
ubuntu-14.04
mediarecorder
servicenow
procmon
liquidsoap
collision-detection
doctrine2
apache-httpclient-4.x
angular-universal
elastalert
tmux
aggregate
popup
tag-cloud
bookmarklet
reportlab
gnu-screen
javaagents
opengraph
pumping-lemma
uipath
datastax-enterprise
scalatest
rancher
cqlsh
loopback
imdb
scene7
tunnel
stencyl
jquery-inputmask
office-interop
google-cloud-powershell
collation
paperclip
rexx
apiman
libzip
amazon-fire-tv
niagara-ax
hierarchical-clustering
history
visio-2010
openpgp.js
aws-rds
sharpssh
r-commander
try-catch-finally
petapoco
tsc
timex
lightspeed
gdi
treelist
calc
sqldataadapter
dday
opendolphin
mojolicious
redquerybuilder
persian
windows-phone-8-emulator
exchange-server-2007
cyberduck
p4python
page-refresh
pymol
douglas-peucker
jsonschema2pojo
qf-test
gnip
system.net
pytz
xts
rpt
angular-file-upload
pyalgotrade
twitter-finagle
episerver-7
ekevent
xcode5.1
grape-api
static-class
nokogiri
azure-pack
cocotron
spawn
simplemembership
derived-class
states
dancer
eeprom
scsf
visual-leak-detector
zend-validate
httppostedfilebase
file-processing
meego-harmattan
text-manipulation
nscharacterset
oaw
database-agnostic
silverlight-2.0
for-xml
file-storage
opengl-to-opengles
onresize

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App