•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the ASP.NET section within the Web Development category of DaniWeb, a massive community of 402,510 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,719 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our ASP.NET advertiser: Lunarpages ASP Web Hosting
Views: 1918 | Replies: 73 | Solved
![]() |
•
•
Join Date: Apr 2005
Posts: 129
Reputation:
Rep Power: 4
Solved Threads: 0
that what i do but when i log in it appear an error
here is code with session statment
•
•
•
•
Conversion from string"some one" to type "Double" is not valid
here is code with session statment
Dim x As String
Dim u As String
u = Session.Contents("user")
x = Session(u) = 0
If Session("user") = 0 Then at this statement the error appear Server.Transfer("login.aspx")
Else
x = Session("user")
cmd = New OleDbCommand
Dim getname = "SELECT member_userName FROM member/product WHERE member_userName = '" & (x & "'")
cmd.CommandText = getname
Dim l As String = cmd.ExecuteScalar()•
•
Join Date: Sep 2007
Posts: 1,057
Reputation:
Rep Power: 3
Solved Threads: 61
oh that's why! First of all, before I get into it, check your syntax on the getname SELECT statement near the "x". Should drop the "(" before the x and everything after it.
The problem is that you cannot assign the values like that. x = sessionuser = 0, it doesn't work that way. You first have to assign session(u) = 0 then x = Session(u). And "u" was already set to the username of "some one". You Then you tried to set it to zero, but you are setting it to an integer, not a string. You must put it exactly as:
Session("user") = "0"
That way it treats it as a string. Without the quotes, it treats it as an integer (or double). But can I ask you this.. why are you setting it to zero anyway?
From what I see, you set "u" equal to a sessions.contents, then you're setting x equal to zero... I am so confused on this one. It seems as if there is no point for x in the first part. Session("user") will be different than Session(u) just about Always.
And becareful about server.transfer, it transfer's the page correctly, but the url will stay the same. Redirect will transfer the page and change the url.
The problem is that you cannot assign the values like that. x = sessionuser = 0, it doesn't work that way. You first have to assign session(u) = 0 then x = Session(u). And "u" was already set to the username of "some one". You Then you tried to set it to zero, but you are setting it to an integer, not a string. You must put it exactly as:
Session("user") = "0"
That way it treats it as a string. Without the quotes, it treats it as an integer (or double). But can I ask you this.. why are you setting it to zero anyway?
From what I see, you set "u" equal to a sessions.contents, then you're setting x equal to zero... I am so confused on this one. It seems as if there is no point for x in the first part. Session("user") will be different than Session(u) just about Always.
And becareful about server.transfer, it transfer's the page correctly, but the url will stay the same. Redirect will transfer the page and change the url.
•
•
Join Date: Sep 2007
Posts: 1,057
Reputation:
Rep Power: 3
Solved Threads: 61
well that session was set at first to be a string. Your only hope is to then set the session("user") to nothing then set it again to zero. That should work for you.
Session("user") = Nothing
Session("user") = 0
or user a completely different Session object for the user.
Session("user") = Nothing
Session("user") = 0
or user a completely different Session object for the user.
Last edited by SheSaidImaPregy : Jan 17th, 2008 at 4:01 pm.
•
•
Join Date: Apr 2005
Posts: 129
Reputation:
Rep Power: 4
Solved Threads: 0
STILL THE SAME PROBLEM IN INSERT NOT SOLVED YET
Partial Class cart
Inherits System.Web.UI.Page
Dim con As OleDbConnection
Dim cmd As OleDbCommand
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim con As OleDbConnection
con = New OleDbConnection
con.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source='C:\Documents and Settings\USER\Desktop\my\WebSite4\App_Data\EC.mdb';Persist Security Info=True"
If con.State = Data.ConnectionState.Closed Then
con.Open()
End If
End Sub
Protected Sub getproduct_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles getproduct.Click
Dim x As String
x = Session("user")
Dim LongTimeString As String = ""
Dim DateToString As String = ""
Dim ShortTimeString As String = ""
Dim LongDateString As String = ""
Dim Daysinmonth As Integer = 0
Dim ErrorStr As String = ""
Dim ErrorStr1 As String = ""
con = New OleDbConnection
Dim cmd As OleDbCommand = New OleDbCommand
con.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source='C:\Documents and Settings\USER\Desktop\my\WebSite2\App_Data\EC.mdb';Persist Security Info=True"
If con.State = Data.ConnectionState.Closed Then
con.Open()
End If
Dim OrderDate = System.DateTime.Now
LongTimeString = OrderDate.ToLongTimeString
Daysinmonth = System.DateTime.DaysInMonth(OrderDate.Year, OrderDate.Month)
DateToString = OrderDate.ToString
ShortTimeString = OrderDate.ToShortTimeString
LongDateString = OrderDate.ToLongDateString
If (product.Text = "") Then
ErrorStr = ErrorStr & " Please Enter Product number, "
End If
If (Quantity.Text = "") Then
ErrorStr1 = ErrorStr1 & " Please Enter Product quantity, "
End If
Dim pri = "SELECT price FROM product WHERE ProductNO='" & product.Text & "'"
cmd.Connection = con
cmd.CommandText = pri
Dim s As String = cmd.ExecuteScalar()
Dim Add As String
If Session("user") = Nothing Then
Response.Redirect("login.aspx")
Else
Add = "INSERT INTO order (OrderNo, quantity, price, date, member_UserName, Product_Number)Values (1," & "Quantity.Text" & "," & "pri" & "," & Daysinmonth & "," & x & "," & "product.Text" & ");"
cmd.Parameters.AddWithValue("?OrderNo", 2)
cmd.Parameters.AddWithValue("?quantity", Quantity.Text)
cmd.Parameters.AddWithValue("? price", pri)
cmd.Parameters.AddWithValue("?date", Daysinmonth)
cmd.Parameters.AddWithValue("?member_UserName", x)
cmd.Parameters.AddWithValue("?Product_Number", product.Text)
cmd.CommandText = Add
End If
Try
cmd.ExecuteNonQuery()
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Protected Sub remove_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles remove.Click
Dim x As New OleDbCommand
x.Connection = con
x.CommandType = CommandType.Text
x.CommandText = " DELETE * FROM order WHERE Product_Number='" & productNum.Text & "'"
x.ExecuteNonQuery()
Response.Write(" Product number# " & productNum.Text & " have been removed from your cart.<BR><BR>" & vbCrLf)
End Sub
Protected Sub check_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles check.Click
MsgBox("Thank you for ordering we hope you visit us again ")
End Sub
End Class Last edited by some one : Jan 18th, 2008 at 10:33 am.
•
•
Join Date: Sep 2007
Posts: 1,057
Reputation:
Rep Power: 3
Solved Threads: 61
for better debugging as it seems as if it is a problem in your code, trade out your TRY CATCH statement for this:
This one will give you the exception that the database is throwing.
Try cmd.ExecuteNonQuery() Catch ex As OleDbException MsgBox(ex.Message) End Try
•
•
Join Date: Sep 2007
Posts: 1,057
Reputation:
Rep Power: 3
Solved Threads: 61
nvm, this is why:
dd = "INSERT INTO order (OrderNo, quantity, price, date, member_UserName, Product_Number)Values (1," & "Quantity.Text" & "," & "pri" & "," & Daysinmonth & "," & x & "," & "product.Text" & ");"
You cannot use the quotes like that, here:
Gotta remove the quotes around your Text fields
dd = "INSERT INTO order (OrderNo, quantity, price, date, member_UserName, Product_Number)Values (1," & "Quantity.Text" & "," & "pri" & "," & Daysinmonth & "," & x & "," & "product.Text" & ");"
You cannot use the quotes like that, here:
Add = "INSERT INTO order (OrderNo, quantity, price, date, member_UserName, Product_Number)Values (1," & Quantity.Text & "," & pri & "," & Daysinmonth & "," & x & "," & product.Text & ");"
Last edited by SheSaidImaPregy : Jan 18th, 2008 at 12:01 pm.
![]() |
•
•
•
•
•
•
•
•
DaniWeb ASP.NET Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
- Code 19 Registry Error (Windows NT / 2000 / XP / 2003)
- Why won't this code work? (VB.NET)
- Need help with DirectX code (C)
- Tutorials & Code Submissions - Questions? (DaniWeb Community Feedback)
- Some Basic Code Hopefully (Help Needed) (HTML and CSS)
Other Threads in the ASP.NET Forum
- Previous Thread: What is Talkswitch?
- Next Thread: I am struk up with this problem



Linear Mode