I
igitur
I have a populated DataSet that I want to upload to a DB2 table. There
isn't a stored procedure, so I'll have to do it with a direct INSERT
statement.
The OleDbCommandBuilder doesn't work to generate an INSERT statement
automatically, so I have to build my own. This is a documented
feature.
I tried doing something like this:
OleDbCommand insertCommand = new OleDbCommand("INSERT INTO
MYSCHEMA.MYTABLE (COL1, COL2, COL3) VALUES (@P1, @P1, @P3)",
connection);
insertCommand.CommandType = CommandType.Text;
insertCommand.Parameters.Add("@P1", OleDbType.Integer, 0, "column1");
insertCommand.Parameters.Add("@P2", OleDbType.VarChar, 50, "column2");
insertCommand.Parameters.Add("@P3", OleDbType.VarChar, 10, "column3");
dataAdapter.InsertCommand = insertCommand;
dataAdapter.Update(myTable); // and this crashes horribly. It
doesn't like the @P1 type parameters that I tried.
Obviously column1, column2 and column3 are columns in my dataset.
I really don't want to loop through all the records 1 by 1 and generate
a separate INSERT statement for each of them. I'd like to use the
..Update functionality.
Anybody got a solution to this?
thanks,
Francois
isn't a stored procedure, so I'll have to do it with a direct INSERT
statement.
The OleDbCommandBuilder doesn't work to generate an INSERT statement
automatically, so I have to build my own. This is a documented
feature.
I tried doing something like this:
OleDbCommand insertCommand = new OleDbCommand("INSERT INTO
MYSCHEMA.MYTABLE (COL1, COL2, COL3) VALUES (@P1, @P1, @P3)",
connection);
insertCommand.CommandType = CommandType.Text;
insertCommand.Parameters.Add("@P1", OleDbType.Integer, 0, "column1");
insertCommand.Parameters.Add("@P2", OleDbType.VarChar, 50, "column2");
insertCommand.Parameters.Add("@P3", OleDbType.VarChar, 10, "column3");
dataAdapter.InsertCommand = insertCommand;
dataAdapter.Update(myTable); // and this crashes horribly. It
doesn't like the @P1 type parameters that I tried.
Obviously column1, column2 and column3 are columns in my dataset.
I really don't want to loop through all the records 1 by 1 and generate
a separate INSERT statement for each of them. I'd like to use the
..Update functionality.
Anybody got a solution to this?
thanks,
Francois