Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion Groups
DB Engine
SQL ServerMSDESQL Server CE
Services
Analysis (Data Mining)Analysis (OLAP)DTSIntegration ServicesNotification ServicesReporting Services
Programming
CLRConnectivitySQLXML
Other Technologies
ClusteringEnglish QueryFull-Text SearchReplicationService Broker
General
Data WarehousingPerformanceSecuritySetupSQL Server ToolsOther SQL Server Topics
DirectoryUser Groups
Related Topics
MS AccessOther DB ProductsMS Server Products.NET DevelopmentVB DevelopmentJava DevelopmentMore Topics ...

SQL Server Forum / DB Engine / SQL Server CE / April 2008

Tip: Looking for answers? Try searching our database.

Insert during Select

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Simone - 17 Apr 2008 12:31 GMT
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 MVP - 17 Apr 2008 14:19 GMT
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

> Hello.
>
[quoted text clipped - 40 lines]
>
> Thanks,Simon.

Signature

Ginny Caughey
Device Application Development MVP

www.wasteworks.com
Software for Waste Management

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.