[quoted text, click to view] Mark wrote:
> Apologies for cross posting -
This is a multipost, not a crosspost. There is a difference. Crossposting:
sometimes OK. Multiposting: never ok.
[quoted text, click to view] > I think this is a more appropriate
> newsgroup than the general one I originally posted in.
>
> *********************
>
> Hi - I've got a really strange problem I can't explain - when I add
> new values into my database (Access) it multiplies them by 100 - for
> example if I enter on my form the values:
>
> 10.50
> 7.50
> 5.50
>
> They go into the database as:
>
> 1050
> 750
> 550
>
> The field in Access is a Double type, nullable, and set to default to
> 0.
>
> My code to add it is:
> (the response.writes are what product the numbered output above - so I
> know what the form is posting, and subsequently what the database has
> in its fields)
>
> if Request("selected") <> "" then
> response.write(Request("RetailPrice"))
> response.write("<br>")
> response.write(Request("Price"))
> response.write("<br>")
> response.write(Request("CostPrice"))
> response.write("<br>")
> ProductsRS.AddNew
> ProductsRS("Product")=Request("Product")
> ProductsRS("Description")= Request("Description")
> ProductsRS("StockNumber")=Request("StockNumber")
> ProductsRS("CategoryID")= Request("CategoryID")
> ProductsRS("RetailPrice")=Request("RetailPrice")
> ProductsRS("Price")=Request("Price")
> ProductsRS("CostPrice")=Request("CostPrice")
> ProductsRS.Update
> ProductsRS.Requery
> ProductID=ProductsRS("ProductID")
> response.write(ProductsRS("RetailPrice"))
> response.write("<br>")
> response.write(ProductsRS("Price"))
> response.write("<br>")
> response.write(ProductsRS("CostPrice"))
> response.write("<br>")
>
Don't use recordsets to modify data. My suggestion would be to use a saved
parameter query. Open your database in Access, go to the Queries tab, and
create a new query in Design View (there should be a button on the database
window for this, depending on what version of Access you are using). Close
the Choose Table dialog without selecting a table, and immediately switch to
SQL View (toolbar button, menu option, or right-click context menu). Type
this into the window (assuming the table's name is "Products"):
INSERT INTO Products (Product, Description,StockNumber,
CategoryID,RetailPrice,Price,CostPrice)
VALUES ([pProduct], [pDescription],[pStockNumber],
[pCategoryID],[pRetailPrice],[pPrice],[pCostPrice])
If you test it by clicking the Execute button in the toolbar, you will be
prompted for each parameter value. Enter some test values and then look at
the data in the table to verify that the data was entered correctly. If so,
save the query as "qInsProduct", and you are now ready to execute it from
asp:
dim cn, rs, sSQL, newID
cn.open "provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=p:\ath\to\database.mdb"
'I would assign the values from the Request object to variables and
'validate them at this point, however, just to save space and time,
'I will illustrate using the request variables directly - YOU SHOULD
'NOT DO IT THIS WAY - validate your user's input.
'In addition, you should not make the runtime engine search
'all the Request collections for your variables. Always specify
'which collection contains the variable. IE, request.form("var")
' instead of reques("var"). Since I did not know whether you
'were passing by POST or GET, I will not specify the collection
'in this example. But you should!
cn.qInsProduct Request("Product"), _
Request("Description"), Request("StockNumber"), _
Request("CategoryID"), Request("RetailPrice"), _
Request("RetailPrice"), Request("Price"), Request("CostPrice")
sSQL = "Select @@IDENTITY"
Set rs = cn.Execute(sSQL,,1)
newID=rs(0)
sSQL="Select Product, Description,StockNumber, " & _
"CategoryID,RetailPrice,Price,CostPrice " & _
"FROM Products WHERE ProductID = " & newID
Set rs=cn.Execute(sSQL,,1)
'etc.
If the incorrect values are still being displayed, verify that they were
stored that way by opening the database in Access and looking at the data.
If they were stored incorrectly, then there is probably a Regional Settings
issue that should have been taken care of by passing the values by
parameter. Let us know if this is the case.
If the correct values are in the database, then there is a display issue,
probably being caused by Regional Settings, again let us know.
Bob Barrows
--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.