Start a new topic Input Byte[] into image

I need to make the sql code in c# to execute to add a byte array as I am transferring the data from one database to another. I am able to get the data out of the first one and put all but the image(byte[]) into the second one

Have you tried:  

INSERT INTO transfertable 
(f1, f2, f3,........., imagefield) 
SELECT f1, f2, f3,........., imagefield 
FROM originaltable


What you need to be sure when passing data into an INSERT command (or really any case you're passing data to a SQL statement) is that you use parameters.  This preserves the .NET type all the way into the database engine.  We have a few examples in our documentation at:

ADO.NET - Common Operations

but here's the relevant sample under Inserting Data using a Parameterized Command:


using (VistaDBConnection connection = new VistaDBConnection())
    connection.ConnectionString = @"Data Source=C:\mydatabase.vdb5";

    using (VistaDBCommand command = new VistaDBCommand())
        int Age = 21;

        command.Connection = connection;
        command.CommandText = "INSERT INTO MyTable (MyColumn) VALUES (@age)";
        command.Parameters.Add("@age", Age);


Login to post a comment