6 Replies - 5815 Views - Last Post: 27 August 2013 - 07:38 AM

#1 twins2me  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 65
  • Joined: 30-July 13

Error converting data type varchar to numeric

Posted 22 August 2013 - 09:18 AM

I keep getting this error when I am trying to do an INSERT from my VB.NET application. In the application, user selects the file to pull data from to then insert into the database. It's not telling me where exactly the error is in my code and I'm still new to using both programs and can't find the error myself.

I have my tables set up as:

CREATE TABLE InlayTestValue
(
InlayName varchar(50)NOT NULL,
InlayNbr varchar(10) NOT NULL,
TestName varchar(50) NOT NULL,
ProductName varchar(50) NOT NULL,
DegreeNote varchar(50),
AngleNbr varchar(10) NOT NULL,
AntennaNbr varchar(10) NOT NULL,
FrequencyNbr varchar(10) NOT NULL,
Transmitted_Power dec(7,3),
Backscattered_Power dec(7,3),
Backscattered_Signal_Phase dec(7,3),
Electric_Field_Strength dec(7,3),
DeltaRCS dec(7,3),
Power_on_Tag_Forward dec(7,3),
Power_on_Tag_Reverse dec(7,3),
Theoretical_Read_Range_Forward dec(7,3),
Theoretical_Read_Range_Reverse dec(7,3));



and this is my insert code in the application:

 'Connect to the database
                        con.ConnectionString = "Data Source = server; Initial Catalog=database; Integrated Security=SSPI"
                        con.Open()
                        cmd.Connection = con
                        cmd.CommandText = "INSERT INTO InlayTestValue (InlayName, InlayNbr, TestName, ProductName, DegreeNote, AngleNbr, AntennaNbr, FrequencyNbr, Transmitted_Power, Backscattered_Power, Backscattered_Signal_Phase, Electric_Field_Strength, DeltaRCS, Power_on_Tag_Forward, Power_on_Tag_Reverse, Theoretical_Read_Range_Forward, Theoretical_Read_Range_Reverse) VALUES ('" & InlayNameTextBox.Text & "', '" & InlayNbrTextBox.Text & "', '" & TestCheckedListBox.SelectedItem & "', '" & ProductCheckedListBox.SelectedItem & "', '" & antHdr(1) & "', '" & antHdr(3) & "', '" & antHdr(5) & "', '" & antData(0) & "', '" & antData(1) & "', '" & antData(2) & "', '" & antData(3) & "', '" & antData(4) & "', '" & antData(5) & "', '" & antData(6) & "', '" & antData(7) & "', '" & antData(8) & "', '" & antData(9) & "')"
                        cmd.ExecuteNonQuery()
                        con.Close()



I get the error on the line with the execute non query.

The program was working fine one minute and importing the sample files just fine until I imported a duplicate file and now I can't import anything.

This post has been edited by twins2me: 22 August 2013 - 09:24 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Error converting data type varchar to numeric

#2 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 13491
  • View blog
  • Posts: 53,888
  • Joined: 12-June 08

Re: Error converting data type varchar to numeric

Posted 22 August 2013 - 09:26 AM

First thing.. using parameters (instead of trying to concatenate a string together) helps alleviate data conversion issues. Next - throws this in a try/catch (on the VB.NET side) with a breakpoint on the exception.. and when it chucks an exception examine examine what you are trying to concatenate... something isn't lining up right and what you assume is a number isn't parsing as such.
Was This Post Helpful? 0
  • +
  • -

#3 twins2me  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 65
  • Joined: 30-July 13

Re: Error converting data type varchar to numeric

Posted 22 August 2013 - 09:33 AM

How do I do that?
Was This Post Helpful? 0
  • +
  • -

#4 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 13491
  • View blog
  • Posts: 53,888
  • Joined: 12-June 08

Re: Error converting data type varchar to numeric

Posted 22 August 2013 - 09:51 AM

I am not sure what "that" means. Parameters? Debugging? Try/catch? Examining variables while in debug mode? Understanding data conversions?
Was This Post Helpful? 0
  • +
  • -

#5 twins2me  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 65
  • Joined: 30-July 13

Re: Error converting data type varchar to numeric

Posted 22 August 2013 - 09:59 AM

All of it. I didn't learn of parameters until the other day. How do I incorporate them into my code?

How do I use the Try/Catch to examine the variables? etc?
Was This Post Helpful? 0
  • +
  • -

#6 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 13491
  • View blog
  • Posts: 53,888
  • Joined: 12-June 08

Re: Error converting data type varchar to numeric

Posted 22 August 2013 - 10:03 AM

You read up on them.

try catch from MSDN. http://msdn.microsof...y/fk6t46tz.aspx

parameter http://msdn.microsof...parameters.aspx
http://msdn.microsof...parameters.aspx

OleDb Basics in VB.Net
A Really Simple Database Create a Database using Access & VB.net Express 2008

Debugging
Was This Post Helpful? 1
  • +
  • -

#7 twins2me  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 65
  • Joined: 30-July 13

Re: Error converting data type varchar to numeric

Posted 27 August 2013 - 07:38 AM

Thank you! These have been helpful.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1