Click here to Skip to main content
15,894,343 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi all

Please find the below details and help me to solve the prob

code:

VB
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:
SQL
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
Comments
StianSandberg 26-Apr-13 9:24am    
your code is vulnerable to sql-injections. You really should do something about it...
Jochen Arndt 26-Apr-13 9:36am    
With sqlite, you must pass NULL as first value for the ID field when it is the primary key.

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.
SQL
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.
 
Share this answer
 
Comments
[no name] 26-Apr-13 9:41am    
Thanks Griff...
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.

C#
Response.Write(cmd.CommandText);
Response.End();
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900