Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Data;
- using System.Data.OleDb;
- namespace ConsoleApplication1
- {
- class Program
- {
- static void Main(string[] args)
- {
- String jetConnection = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=C:\jetsample.mdb;";
- ADOX.CatalogClass cat = new ADOX.CatalogClass();
- cat.Create(jetConnection);
- using(OleDbConnection conn = new OleDbConnection(jetConnection))
- {
- conn.Open();
- using(OleDbCommand cmd = new OleDbCommand("CREATE TABLE test ([ID] INTEGER, [TestDouble] DOUBLE, [TestText] TEXT, [TestDate] DATE, [TestInt] INTEGER)",conn))
- {
- cmd.CommandType = CommandType.Text;
- cmd.ExecuteNonQuery();
- }
- using (OleDbCommand cmd = new OleDbCommand("INSERT INTO [Test] VALUES (@id, @testDouble, @testText, @testDate, @testInt)", conn))
- {
- OleDbParameter id = cmd.Parameters.Add("@id", OleDbType.Integer);
- OleDbParameter testDouble = cmd.Parameters.Add("@testDouble", OleDbType.Double);
- OleDbParameter testText = cmd.Parameters.Add("@testText", OleDbType.VarWChar);
- OleDbParameter testDate = cmd.Parameters.Add("@testDate", OleDbType.Date);
- OleDbParameter testInt = cmd.Parameters.Add("@testInt", OleDbType.Integer);
- DateTime start = DateTime.Now;
- for (int index = 1; index <= 2000000; index++)
- {
- if (index % 1000 == 0)
- {
- System.Diagnostics.Debug.WriteLine(((TimeSpan)(DateTime.Now - start)).Milliseconds);
- start = DateTime.Now;
- }
- id.Value = index;
- testDouble.Value = index;
- testText.Value = String.Format("{0} DBL", index);
- testDate.Value = DateTime.Now.AddMilliseconds(index);
- testInt.Value = index;
- cmd.ExecuteNonQuery();
- }
- }
- }
- }
- }
- }
- Set cn = CreateObject("ADODB.Connection")
- strFile="C:ltd.mdb"
- strCon="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" _
- & strFile & ";"
- cn.Open strCon
- strSQL="INSERT INTO tableX ( Name1,Name2 ) " _
- & "SELECT Name1,Name2 " _
- & "FROM [ltd.txt] IN '' [Text;Database=c:docs;HDR=YES;]"
- cn.Execute strSQL
Add Comment
Please, Sign In to add comment