Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: Windows WPF VB.NET
Hi all
 
Please find the below details and help me to solve the prob
 
code:
 
 Dim con1 As New SqlConnection("Data Source=KITT7-PC;Initial Catalog=project;User ID=sa;Password=1234")
 
        con1.Open()
        Dim cmd As New SqlCommand("insert into CompanyCreation values('" & txtCompanyName.Text & "','" & txtCompanyCode.Text & "','" & txtCompanyAlias.Text & "','" & txtAddress.Text & "','" & cmbCity.Text & "','" & txtPincode.Text & "','" & cmbState.Text & "','" & txtCountry.Text & "','" & txtPh1.Text & "','" & txtPh2.Text & "','" & txtPh3.Text & "','" & txtFax.Text & "','" & txtMobile.Text & "','" & txtEmail.Text & "','" & txtWebsite.Text & "','" & txtServiceTAX.Text & "','" & txtVATNo.Text & "','" & cmbTaxing.Text & "','" & cmbFinYear.Text & "','" & txtCurrency.Text & "','" & txtITPan.Text & "','" & cmbAccountingSystem.Text & "','" & txtTIN.Text & "','" & txtCST.Text & "','" & txtWardno.Text & "','" & txtAdminUser.Text & "','" & txtAdminPass.Text & "','" & txtConfirmPass.Text & "','" & txtcodex.Text & "','" & txtPass.Text & "','" & txtConfirmPass.Text & "')", con1)
        cmd.ExecuteNonQuery()
        Catch ex As Exception
 
        End Try
 
database:
ID	int	
CompanyCode	varchar(50)	
CompanyName	varchar(25)	
Alias	varchar(100)	
AgentType	varchar(100)	
Address	varchar(25)	
City	varchar(25)	
Pincode	int	
State	varchar(100)	
Country	varchar(100)	
Ph1	numeric(10, 0)	
Ph2	numeric(10, 0)	
Ph3	numeric(10, 0)	
Fax	numeric(10, 0)	
Mobile	numeric(10, 0)	
Email	nvarchar(30)	
Website	nvarchar(30)	
Taxing	varchar(30)	
ServiceTax	decimal(10, 2)	
VATNo	int	
FinancialYearStart	int	
IndianCurrencySymbol	varchar(25)	
ITPan	varchar(25)	
AccountingSystem	varchar(15)	
Account	varchar(25)	
TIN	numeric(10, 0)	
CST	varchar(25)	
WardNo	int	
AdminUser	varchar(30)	
AdminPass	varchar(30)	
LocatonofDataSave	varchar(50)	
Codex	int	
 
I am getting the error saying
Error converting data type varchar to numeric.
 
Please tell me where is the problem.
Posted 26-Apr-13 4:19am
Comments
AlluvialDeposit at 26-Apr-13 9:24am
   
your code is vulnerable to sql-injections. You really should do something about it...
Jochen Arndt at 26-Apr-13 9:36am
   
With sqlite, you must pass NULL as first value for the ID field when it is the primary key.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

What a mess!
There are a number of things you need to do before you will get a good idea what is happening here:
1) Use Parametrized queries. As AlluvialDeposit says, you are wide open to SQL injection attacks as your code stands. Parametrized queries will also make you code much, much more readable.
2) Name the fields you are inserting into.
INSERT INTO CompanyCreation (ID, CompanyCode, CompanyName, ...) VALUES (...
That way, SQL knows exactly which value you want to insert into which column.
 
It would also be a very good idea to convert the values to an appropriate datatype before passing them through to SQL - that way if the user makes a mistake, you can issue a specific error message instead of your app failing with an exception because SQL can't convert a value either.
 
Doing those will probably get rid of your problem as well as improving usability, readability, reliability and maintainability.
  Permalink  
Comments
Snehasish Nandy at 26-Apr-13 9:41am
   
Thanks Griff...
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

The error means that you are trying to insert a string value into a number column. Try to write out your generated sql-query before you execute it to see if you can spot the error.
 
Response.Write(cmd.CommandText);
Response.End();
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 350
1 Jochen Arndt 190
2 Richard MacCutchan 135
3 Sergey Alexandrovich Kryukov 130
4 DamithSL 95
0 OriginalGriff 6,045
1 DamithSL 4,601
2 Maciej Los 4,087
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,310


Advertise | Privacy | Mobile
Web03 | 2.8.141220.1 | Last Updated 26 Apr 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100