Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Implicit conversion from data type varchar to varb

Author  Topic 

mrtanvirali
Starting Member

41 Posts

Posted - 2008-12-02 : 08:57:35
Dear All,

I want to save html tags into the database but the query giving me error that

"Implicit conversion from data type varchar to varbinary is not allowed. Use the CONVERT function to run this query"

I am using simple query:

INSERT INTO NewsInfo (Id, News, PageId, Description) values(@Id, @News, @PageId, @Description)

@News Consists of html string e.g. <p>hello world</p><strong>bold text</strong> etc.


please help me to solve this

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-12-02 : 09:03:15
INSERT INTO NewsInfo (Id, News, PageId, Description) values(@Id, @News, @PageId, CAST(@Description AS VARBINARY(MAX)))


E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page

jholovacs
Posting Yak Master

163 Posts

Posted - 2008-12-02 : 14:13:47
What is the DDL definition of the NewsInfo table?

___________________________
Geek At Large
Go to Top of Page

mrtanvirali
Starting Member

41 Posts

Posted - 2008-12-03 : 00:10:44
Thanks both of you for reply,

It was a little ddl fault:

First DDL was: (jsut look at the Description field's datatype)
INSERT INTO [IITSolutions].[dbo].[web_NewsInfo]
([UserId],[News],[PageId],[Description])
VALUES(<UserId, int,>,<News, varchar(3000),>,<PageId, int,>,<Description, varbinary(100),>)

and i was storing '' into the description column
but now i've changed Description field's datatype form varbinary to varchar, that's done

Changed: DDL
INSERT INTO [IITSolutions].[dbo].[web_NewsInfo]
([UserId],[News],[PageId],[Description])
VALUES(<UserId, int,>,<News, varchar(3000),>,<PageId, int,>,<Description, varchar(100),>)
Go to Top of Page
   

- Advertisement -