Groups | Blog | Home
all groups > inetserver asp db > august 2004 >

inetserver asp db : MS Access - problem with Double type field



Mark
8/26/2004 4:51:35 AM
Apologies for cross posting - 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>")

Can anyone please try and help me with this.

Kind regards, Mark


*** Sent via Developersdex http://www.developersdex.com ***
Mark
8/26/2004 6:51:34 AM
Hi Bob - thank you - the code works well.

At least it works fine locally - but still not on the host.

They are 1and1 and I did have some trouble with regional settings on
their sql server when I was doing something on that (they were
displaying a comma instead of a decimal point).

I think they're German, so the regional settings suggestion sounds like
it could be the issue.

I have tried setting <% session.lcid=2057 %> at the top of my script,
but it is still going in to the database seemingly just taking out the
decimal point. Are there any other settings I can use to ensure they
are enforced, and not being overwritten by 1and1s IIS setup?

Thanks again, Mark



*** Sent via Developersdex http://www.developersdex.com ***
Mark Schupp
8/26/2004 7:54:17 AM
Try this:

oldLCID = session.lcid

session.lcid=2057

nPrice = CDbl(Request("Price"))
nCostPrice = CDbl(Request("CostPrice"))
..
..
..

session.lcid = oldLCID

ProductsRS("Price")= nPrice
ProductsRS("CostPrice")= nCostPrice
..
..
..

--
Mark Schupp
Head of Development
Integrity eLearning
www.ielearning.com


[quoted text, click to view]

Bob Barrows [MVP]
8/26/2004 9:09:40 AM
[quoted text, click to view]

This is a multipost, not a crosspost. There is a difference. Crossposting:
sometimes OK. Multiposting: never ok.

[quoted text, click to view]

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.

Bob Barrows [MVP]
8/26/2004 10:17:59 AM
[quoted text, click to view]

I have little experience with internationalization issues. I was under the
mistaken impression that passing the values by parameter would solve those
issues. You might try using the CDbl function when passing the values to see
if that helps:

cn.qInsProduct ...,CDbl(Request("...")), ...

If that does not do it, then we may need to resort to dynamic sql, replacing
the periods with commas.

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.

Mark
8/27/2004 5:21:32 AM
Hi - thanks for the help.

This has now been resolved - although I'm not really sure which part was
the key - but I now have a far more efficient 'query' accepting the data
- The CDbl did seem to help - although setting the lcid within the page
did not - I added a global.asa file, which set the lcid to my locale
(2057), at my hosts instruction.

Thanks again, Mark



*** Sent via Developersdex http://www.developersdex.com ***
Mark
8/27/2004 5:51:32 AM
Hi - thanks for the help.

This has now been resolved - although I'm not really sure which part was
the key - but I now have a far more efficient 'query' accepting the data
- The CDbl did seem to help - although setting the lcid within the page
did not - I added a global.asa file, which set the lcid to my locale
(2057), at my hosts instruction.

Thanks again, Mark



*** Sent via Developersdex http://www.developersdex.com ***
AddThis Social Bookmark Button