i tried to update the binary data to a sqltable from .net.i used the codings like this
BinaryReader
error:
Implicit conversion from data type varchar to varbinary(max) is not allowed. Use the CONVERT function to run this query.
error will occur how can i solve this
br = new BinaryReader(FileUpload1.PostedFile.InputStream);byte[] b1 = br.ReadBytes(FileUpload1.PostedFile.ContentLength);
string strconn = @"data source=.\sqlexpress;initial catalog=jobs;uid=sa;pwd=as";
SqlConnection conn = new SqlConnection(strconn);
string q1 = "update register set resume='" + b1 + "' where id='" + id1+ "'";
SqlCommand cmd = new SqlCommand(q1, conn);
SqlDataReader rdr = null;
rdr = cmd.ExecuteReader();
karthi vimalaPosted Mar 29, 2011, 3:10 AM
now i used like this
string q1 = "insert into register(resume) values(@resume) where id = '" + id1 + "'";
SqlCommand cmd = new SqlCommand(q1, conn);cmd.Parameters.Add(new SqlParameter("@resume", (object)b1));
cmd.ExecuteNonQuery ();
the error:
Incorrect syntax near the keyword where error will occur,
karthi vimalaPosted Mar 29, 2011, 3:06 AM
sorry,i got it,i done th error in the line rdr=cmd.executereader();
i correct it by cmd.executenonquery();
Soft CornerPosted Mar 29, 2011, 2:51 AM
Show me your updated code, let me check here.
karthi vimalaPosted Mar 29, 2011, 2:37 AM
in table alos i mentioned varbinary(max).after i changed the executenonquery the error
Error 1 Cannot implicitly convert type 'int' to 'System.Data.SqlClient.SqlDataReader'
error will occur
Soft CornerPosted Mar 29, 2011, 2:29 AM
1. Check with Datatype of Column in Database, i think u have varchar column in DB
2. & Seems to be you are wrong at this statement
SqlDataReader rdr = null;
rdr = cmd.ExecuteReader();
[No need of these two line, remove it from code]
As your query is Updating the table, so use cmd.ExecuteNonQuery()