Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Insert Double value via SQL to database

Posted on 2012-03-28
10
1,832 Views
Last Modified: 2012-03-29
Hi guys,


I am using vb.net and access 2010 database.

I am using an insert statement to send a double value from a grid-view cell to an access database.

The cell contains a double value.

The problem is i am able to send the values with a decimal next to every number which has two zeros following it:

Example:

10.00 , 25.00 , 100.00 (i.e. when i input a number with the decimal point and the following numbers with two consecutive zeros, there is no problem in sending the values to the database using the sql.)

but when i put in any number other than the two zeros after the decimal point such as 10.12, 10.52, 52.41, then i get the following error from the try catch block.

number of query values and destination fields are not the same

this is the way i am using the sql:

dim dblCashIn as double


sql = insert into tblBank (cashInCome) values (dblCashIn);

and i use the executenonquery command to insert the data into the database.

Thanks in advance.
0
Comment
Question by:baabaa_nl
  • 3
  • 3
  • 2
  • +2
10 Comments
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 37779475
What is the locale/culture of the computer?
0
 

Author Comment

by:baabaa_nl
ID: 37779485
dutch and english
0
 
LVL 6

Expert Comment

by:Patrick Tallarico
ID: 37779554
And the column type of the MS Access table is set to double also???  For instance it wouldn't work if it was set to a number of type Integer...
0
How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

 

Author Comment

by:baabaa_nl
ID: 37779563
it was set to currency from the beginning
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 37779565
Is the separator , or . on the system locale?
0
 

Author Comment

by:baabaa_nl
ID: 37779572
at first it was ,

but then i changed it to engish keyboard, but even after that it didnt work
0
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 500 total points
ID: 37779579
Try enclosing the value in single quotes

sql = insert into tblBank (cashInCome) values ('dblCashIn');
0
 
LVL 6

Expert Comment

by:Patrick Tallarico
ID: 37779580
As long as the column is set to the proper amount of digits to the right of the decimal point, you should be able to insert the values, can you set the variable as currency from the beginning?  If so, it should work for you then.

If not, then perhaps you need to convert the double values to currency first...
The following link has some info on those functions.
http://office.microsoft.com/en-us/access-help/type-conversion-functions-HA001229018.aspx
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 37780008
Have you considered creating a parameterized query? It should take care of converting the value for Access on your behalf.

For example:

Using con As New OleDbConnection("[your con string]")
    Using cmd As new OleDBCommand("insert into tblBank (cashInCome) values (?)", con)
        cmd.Parameters.AddWithValue("@someArbitraryName", dblCashIn)

        con.Open()
        cmd.ExecuteNonQuery()
    End Using
End Using

Open in new window


For OleDB, you use a question mark as a placeholder for each parameter you want to add. When you add parameters to the Command object, add them in the order they would naturally appear within the query (left-to-right).
0
 
LVL 49

Expert Comment

by:Gustav Brock
ID: 37780742
The accepted answer cannot be the solution.
It will fail trying to insert the string "dblCashIn" into a the numeric field cashInCome.

You must insert a string expression in the SQL statement, and Str is exactly for this because it always converts the decimal char to a dot:

sql = "insert into tblBank (cashInCome) values (" & Str(dblCashIn) & ");"

/gustav
0

Featured Post

Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
If you find yourself in this situation “I have used SELECT DISTINCT but I’m getting duplicates” then I'm sorry to say you are using the wrong SQL technique as it only does one thing which is: produces whole rows that are unique. If the results you a…
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question