Re: Insert during Select



Simone,

You'll need a second SqlCeCommand object for the inserts. You'll also get better performance if you use a parametized query and just change the parameters on each insert statement.

Ginny

"Simone" <simondj1@xxxxxxxxx> wrote in message news:eZc516HoIHA.5836@xxxxxxxxxxxxxxxxxxxxxxx
Hello.



Can i insert a record in a table B during reading records in a table A (Sql Compact Edition 3.1)?



Something like this:



SqlCeConnection c=new SqlCeConnection("Data Source=\test.sdf");

SqleConnection d=new SqlCeConnection("Data Source=\test.sdf");

SqlCeCommand cmd=new SqlCeCommand(c,"SELECT * FROM TABLE A");

SqlCeCommand cmd1=new SqlCeCommand();

cmd1.Connection=d;

cmd.Connection.Open();

cmd1.Connection.Open();

SqlceDataReader dr=cmd.ExecuteReader();

while (dr.read())

{

string a=dr.GetString(0);

string b=dr.GetString(1);

cmd1.Text="INSERT INTO B VALUES('"+a+"','"+b+"')";

cmd1.ExecuteNonQuery();

}

dr.Close();

c.CLose();

d.Close();



Thanks,Simon.



--

Ginny Caughey
Device Application Development MVP

www.wasteworks.com
Software for Waste Management



.


Loading