Click here to Skip to main content
15,879,326 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear sir,

I want to store data into database through insert query but i facing error
'Implicit conversion from data type varchar to varbinary(max) is not allowed. Use the CONVERT function to run this query.'

Filedata(column Name) Varbinary(Max) datatype

My code are following:-
SqlCommand cmd = new SqlCommand("INSERT INTO CompRecd(ComNo, ComCat, ComSubCat, Whom, City, MobNo, PhoNo, EmailID, FileData,TimeStamp, officer, HouseNo, [from], CompSubCat2, Locality ,FileDataType, Complaint , ipaddress) VALUES('" + compid + "','" + ds.Tables[0].Rows[0]["ComCat"].ToString() + "', '" + ds.Tables[0].Rows[0]["ComSubCat"].ToString() + "','" + ds.Tables[0].Rows[0]["Whom"].ToString() + "','" + ds.Tables[0].Rows[0]["City"].ToString() + "', '" + ds.Tables[0].Rows[0]["MobNo"].ToString() + "','" + ds.Tables[0].Rows[0]["PhoNo"].ToString() + "','" + ds.Tables[0].Rows[0]["EmailID"].ToString() + "','" + ds.Tables[0].Rows[0]["FileData"].ToString() + "', getdate(),'" + item.Value + "','" + ds.Tables[0].Rows[0]["HouseNo"].ToString() + "', '" + ds.Tables[0].Rows[0]["from"].ToString() + "','" + ds.Tables[0].Rows[0]["CompSubCat2"].ToString() + "','" + ds.Tables[0].Rows[0]["Locality"].ToString() + "','" + ds.Tables[0].Rows[0]["FileDataType"].ToString() + "','" + ds.Tables[0].Rows[0]["Complaint"].ToString() + "','" + ds.Tables[0].Rows[0]["ipaddress"].ToString() + "')", cnn);


What I have tried:

I want to store data into database through insert query but i facing error
'Implicit conversion from data type varchar to varbinary(max) is not allowed. Use the CONVERT function to run this query.'
Posted
Updated 2-Aug-16 20:00pm
Comments
Member 12245539 3-Aug-16 1:55am    
Send your SQL Table Script show that I can be verified the DataType......
Nishant.Chauhan80 3-Aug-16 2:20am    
CREATE TABLE [dbo].[CompRecd](
[ID] [numeric](15, 0) IDENTITY(1,1) NOT NULL,
[ComCat] [varchar](200) NULL,
[ComSubCat] [varchar](200) NULL,
[Whom] [varchar](100) NULL,
[HouseNo] [varchar](200) NULL,
[City] [varchar](50) NULL,
[MobNo] [varchar](20) NULL,
[PhoNo] [varchar](25) NULL,
[EmailID] [varchar](200) NULL,
[Complaint] [varchar](1000) NULL,
[TimeStamp] [datetime] NULL,
[FileData] [varbinary](max) NULL,
[ComNo] [varchar](25) NULL,
[officer] [numeric](15, 0) NULL,
[from] [numeric](15, 0) NULL,
[CompSubCat2] [varchar](200) NULL,
[Locality] [varchar](100) NULL,
[Comment] [varchar](200) NULL,
[FileDataType] [varchar](100) NULL,
[ipaddress] [varchar](100) NULL,
[Mark_userid] [int] NULL,
CONSTRAINT [compid_pk] UNIQUE NONCLUSTERED

1 solution

Hello ,
It is clear from the above message that the datatype of one column of your table is varbinary but you are passing varchar value .

so, either redesign the column structure from varbinary to varchar or pass the varbinary as parameter .
Thanks
 
Share this answer
 
Comments
Nishant.Chauhan80 3-Aug-16 2:27am    
no i don't want to change datatype into table
Animesh Datta 3-Aug-16 2:43am    
Then go for second option that i mentioned in my 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