Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
This the .NetFrame work error list
C#
An exception of type 'System.Data.SqlClient.SqlException' occurred in Brp.Core.dll but was not handled in user code

Additional information: Implicit conversion from data type varchar to varbinary(max) is not allowed. Use the CONVERT function to run this query.


This is my model:
C#
//[Required]
       public byte[] Passport { get; set; }

       /*[Required]
       [DataType(DataType.ImageUrl)]
       public string BusinessLogo { get; set; }*/

       //[Required]
       public byte[] BusinessLogo { get; set; }

       [ScaffoldColumn(false)]
       //[Column]
       public string ImageMimeType { get; set; }

       [ScaffoldColumn(false)]
       //[Column]
       public string ImageMimeType2 { get; set; }


This my sequel

C#
SqlConnection con = new SqlConnection(@"Data Source=(localdb)\v11.0;Initial Catalog=Bpr;Integrated Security=True");
               SqlCommand cmd = new SqlCommand();
               cmd.CommandText = String.Format("Insert into Payer(User_Id, PayerName, BusinessName,PhoneNumber,BusinessMobile,PayerAddress,NumberOfStaff,RegDate,DateOfBirth,LocationLatLog,Passport,StateOfOrigin,BusinessLogo, ImageMimeType, ImageMimeType2) values('" + payer.User_Id + "','" + payer.PayerName + "','" + payer.BusinessName + "','"
                + payer.PhoneNumber + "','"+payer.BusinessMobile + "','" + payer.PayerAddress + "','" +payer.NumberOfStaff + "','" +
                payer.RegDate + "','" + payer.DateOfBirth + "','" + payer.LocationLatLog + "','" + payer.Passport + "','"
                + payer.StateOfOrigin + "','" + payer.BusinessLogo + "','" + payer.ImageMimeType + "','" + payer.ImageMimeType2+ "')");
                cmd.Connection = con;
            try
            {
                con.Open();
                cmd.ExecuteNonQuery();
                con.Close();
                return "Success";
            }
        
            catch (Exception es)
            {
                throw es;
            }


Thank you
Posted

1 solution

Try to Execute Query with parameter

C#
// Assuming "conn" is an open SqlConnection
using(SqlCommand cmd = new SqlCommand("INSERT INTO mssqltable(varbinarycolumn) VALUES (@binaryValue)", conn))
{
    // Replace 8000, below, with the correct size of the field
    cmd.Parameters.Add("@binaryValue", SqlDbType.VarBinary, 8000).Value = arraytoinsert;
    cmd.ExecuteNonQuery();
}
 
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