Search code examples
sql-server-cec#-3.0

SQL Server CE Insert multiple rows


I am trying to insert into a SQL Server CE .sdf database file. I'm using these two commands, but I am getting an error when I am trying to insert it from C#:

INSERT INTO LazadaStaging (Id, TrackingNo, Flag) 
VALUES (5068652,'18111111293376', 0); 
INSERT INTO LazadaStaging (Id, TrackingNo, Flag) 
VALUES (5068642,'18111111293370', 0);

Any ideas how to accomplish this? Thanks in advance ;)

public void ExecuteCommand2(string commandText, CommandType commandType, SqlCeConnection sqlConn, SqlCeTransaction sqlTrans, params SqlCeParameter[] parameters)
{
    var command = new SqlCeCommand(commandText);
    command.Connection = sqlConn;
    command.CommandType = commandType;
    //command.CommandTimeout = 10000;

    if (sqlTrans != null) 
         command.Transaction = sqlTrans;

    command.ExecuteNonQuery();

    if (command != null)
    {
        command.Dispose();
    }

    command = null;
}

Solution

  • Have you tried the command:

    INSERT INTO LazadaStaging (Id, TrackingNo, Flag)
    select 5068652,'18111111293376', 0
    union all
    select 5068642,'18111111293370', 0