Question

We have legacy data which is stored in MSSQL database as varchar, even though the data is really binary. In new application we're using OleDbCommand (because we are trying to use common code to access MSSQL+Oracle+Sybase) databases.

I am able to retrieve data from database by performing:

    DA.SelectCommand.CommandText = "select 
sequence_num, summary_num, line_num, CONVERT(varbinary, other_information) other_information 
from alex_test_bin";

However the insert command:

   DA.InsertCommand.CommandText = "insert into alex2_test_bin 
(sequence_num, summary_num, line_num, other_information) 
values(?, ?, ?, CONVERT(varchar, ?))";

throws this error (it happens during 'DA.Update(DT);'):

No value given for one or more required parameters.

Currently I'm just trying to read data from alex_test_bin and insert the data into alex2_test_bin. In between reading and writing, I'm using method 'SetAdded()' on each row from DT, so that all of those rows get inserted.

Is my insert statement wrong? Is there a way to correct it, and be able to use functions inside insert statement? I successfully ran the insert statement manually from sql manager.

Was it helpful?

Solution

Without seeing your full code, it appears that you simply aren't adding the parameters to the DA.InsertCommand.

For each parameter denoted with a ?, you'll need to append an OleDbParameter:

DA.InsertCommand.Parameters.Parameters.Add("@sequence_num", OleDbType.Integer).Value = 42

You need to append these to the command in the same order that they are specified in the insert into statement.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top