These are your problems:
1. You cannot add an integer into an integer column with quotes.
2. You're inserting directly into the SQL statement. Use parameters.
Add = "INSERT INTO order Values ('" & 1 & "','" & Quantity.Text & "','" & pri & "','" & Daysinmonth & "','" & x & "','" & product.Text & "');"
Do this insert statement, and please change your code to use parameters. It will protect you from SQL INJECTION. Cause of right now, I can easily type into any of these fields a drop command and your table will be dropped with all data. Anyway, here's your fixed insert statement.
Add = "INSERT INTO order Values (1," & Quantity.Text & "," & pri & "," & Daysinmonth & "," & x & "," & product.Text & ");"
This assumes all your fields are for integers and not text. Text columns you wrap in your quotes (" '" & .. & "' "), all integer fields you don't (" " & .. & " ")
SheSaidImaPregy
Veteran Poster
1,080 posts since Sep 2007
Reputation Points: 43
Solved Threads: 68
alright, well then there can be a few problems. Make sure all data types of your columns meet the correct ways of entering them (integer - no quotes in query :: text - quotes in query), then make sure you have the right number of columns in the query as you do on your database table. If you have 7 columns on your table and 6 or 8 in your query, you will get this error. Safest bet is to do an insert like this:
INSERT INTO tblname (column1, column2, column3.....) VALUES (value1, value2, value3.....)
Those should be your only two problems. Have you attempted to use parameters instead of direct inserts? It will help reduce errors ten fold.
Add = "INSERT INTO tblname (column1, column2, column3, ....) VALUES (?, ?, ?, ....)"
cmd.Parameters.AddWithValue( "?ColumnName", value )
SheSaidImaPregy
Veteran Poster
1,080 posts since Sep 2007
Reputation Points: 43
Solved Threads: 68
I am actually at work so I can't use the files anyway.
I gave you an example on how to use the parameters. It's quite simple.
Add = "INSERT INTO tblname (column1, column2, column3, ....) VALUES (?, ?, ?, ....)"
cmd.Parameters.AddWithValue( "?Column1", value1 )
cmd.Parameters.AddWithValue( "?Column2", value2 )
cmd.Parameters.AddWithValue( "?Column3", value3 )
Do that for each parameter you have. THey must be in the same order as your SQL statement.
SheSaidImaPregy
Veteran Poster
1,080 posts since Sep 2007
Reputation Points: 43
Solved Threads: 68
Session's are handled as strings normally, so try setting it to ' "0" ' and checking for Session("user") = "0"
SheSaidImaPregy
Veteran Poster
1,080 posts since Sep 2007
Reputation Points: 43
Solved Threads: 68
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.
SheSaidImaPregy
Veteran Poster
1,080 posts since Sep 2007
Reputation Points: 43
Solved Threads: 68
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.
SheSaidImaPregy
Veteran Poster
1,080 posts since Sep 2007
Reputation Points: 43
Solved Threads: 68
for better debugging as it seems as if it is a problem in your code, trade out your TRY CATCH statement for this:
Try
cmd.ExecuteNonQuery()
Catch ex As OleDbException
MsgBox(ex.Message)
End Try
This one will give you the exception that the database is throwing.
SheSaidImaPregy
Veteran Poster
1,080 posts since Sep 2007
Reputation Points: 43
Solved Threads: 68
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:
Add = "INSERT INTO order (OrderNo, quantity, price, date, member_UserName, Product_Number)Values (1," & Quantity.Text & "," & pri & "," & Daysinmonth & "," & x & "," & product.Text & ");"
Gotta remove the quotes around your Text fields :)
SheSaidImaPregy
Veteran Poster
1,080 posts since Sep 2007
Reputation Points: 43
Solved Threads: 68