Hello everyone,
When I call the datacontextInstance.Insertonsubmit() and datacontextinstance.submitChanges(), it clears all the existing data in the database before inserting the new data.
How do I perform a real insert operation?
I want to add new data to the existing table without clearing out the existing data.
Thanks
P.S:
Here's my test code which i tried...
I do change the loop from 100 to 200,300 to 400 etc before i run my app. But,the new records appear in the database and the old records are gone.Code:using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ConsoleApplication2 { class Program { static void Main(string[] args) { DataClasses1DataContext entities = new DataClasses1DataContext(); for (int i = 200; i <= 300; i++) { textdata dt = new textdata(); dt.id = i; dt.ipaddress = "172.168.3.2"; dt.pcname = "testusr"; dt.publicip = "test pub ip"; dt.username = "testusr"; dt.textdata1 = "Some DATA"; dt.dttime = DateTime.Now; entities.textdatas.InsertOnSubmit(dt); entities.SubmitChanges(System.Data.Linq.ConflictMode.ContinueOnConflict); } foreach (textdata dtdata in entities.textdatas) { Console.WriteLine(dtdata.id.ToString()); } entities.Dispose(); Console.ReadLine(); } } }
Here's my App.Config...
HTML Code:<?xml version="1.0" encoding="utf-8" ?> <configuration> <configSections> </configSections> <connectionStrings> <add name="ConsoleApplication2.Properties.Settings.Database1ConnectionString" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Database1.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True" providerName="System.Data.SqlClient" /> </connectionStrings> </configuration>




Reply With Quote