Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need help with CONVERT (text to VARCHAR)

Status
Not open for further replies.

Shfog

Programmer
Aug 24, 2001
20
US
The code below gives me an error message:
"Implicit conversion from datatype 'text' to 'varchar' is not allowed. Use CONVERT function to run this query"
Where and how do I use the convert or cast function?
In the VB Program? In the Stored Procedure? Where?
Thanks for any help.
----------------------------------
VB: Something like this,
myParm(0) = txtName.TEXT
myParm(1) = txtAddress.TEXT
myParm(2) = txtCity.TEXT
cmdmySQL.Execute , myParm
----------------------------------
Stored Procedure
CREATE PROC new_order
DECLARE @Name VARCHAR(50)
@Address VARCHAR(50)
@City VARCHAR(30)
AS INSERT card_orders(
Name, Address, City)
VALUES(
@Name, @Address, @City)
----------------------------------




 
The error probably happens when you call the SP. When you;re not sure about field type of data you pass to the SP, use following (example):
exec new_order convert(varchar(50),left(NameValue,50)), convert(varchar(50),left(AddressValue,50)), convert(varchar(30),left(CityValue,30))
Hope this helps. Vlad Grynchyshyn, MVP
vgryn@softserve.lviv.ua
The professional level of programmer could be determined by level of stupidity of his/her bugs
 
What's the datatypes of the fields in the table? As it looks like you're using ADO, do you need to explicitly declare that the parameters are varchars - is your VB code defaulting them to SQL TEXT fields ? SQL would then complain that it can't change them from text to varchar.
 
It looks like blank text fields in the VB are part of the problem. If all boxes have text, I don't get an error.
Is there a way to send the empty string as NULL in VB?
Or should I adjust my stored procedure? And how?

Thanks
steve@accucopy.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top