ADO.NET Batch Update

Results 1 to 3 of 3

Thread: ADO.NET Batch Update

  1. #1
    Join Date
    Dec 1969

    Default ADO.NET Batch Update

    Please help me I know it is really not that difficult. I have spent hours trying to use a batch update. <BR><BR>-I have succeeded in pulling the DataSet and adding rows to the desired table. <BR><BR>-I get an exception when I use the DataAdapter.Update(myDataSet,"myTable") method. <BR><BR>-BTW Yes I have used the CommmandBuilder correctly earlier in the code. If you can help then great... If you need more info (code), then let me know. <BR><BR>-One more thing... If I use DataSet.AcceptChanges on the before I use the DataAdapter.Update method, then process will complete without errors, but it will NOT write to the database.

  2. #2
    Join Date
    Dec 1969

    Default RE: ADO.NET Batch Update

    Ummm.... can you tell us what the exception is????<BR>Also, relevant code would help too.

  3. #3
    Join Date
    Dec 1969

    Default RE: ADO.NET Batch Update

    Here is the code:<BR><BR>public void cmdRun_Click(object sender, System.EventArgs e)<BR> {<BR> OleDbConnection oldConn, newConn;<BR> OleDbDataAdapter oldDA, newDA;<BR> OleDbCommand oldComm, newComm;<BR> OleDbCommandBuilder oldCB, newCB;<BR> DataSet myRS, newRS;<BR> string aSQL, bSQL;<BR> <BR> newConn = new OleDbConnection("PROVIDER=Microsoft.Jet.OLEDB.4.0; DATA SOURCE=C:\Documents and Settings\derrick\Desktop\Invensys\Invensys.mdb");< BR> aSQL = "Select AccountID, ZipCode, DateTime, Temp FROM 15MinuteDataVer"; <BR> newDA = new OleDbDataAdapter(aSQL, newConn);<BR> newCB = new OleDbCommandBuilder(newDA);<BR> newRS = new DataSet();<BR> newConn.Open();<BR> <BR> newDA.Fill(newRS, "15MinuteDataVer");<BR><BR> oldConn = new OleDbConnection("PROVIDER=Microsoft.Jet.OLEDB.4.0; DATA SOURCE=C:\Documents and Settings\derrick\Desktop\Invensys\Invensys2.mdb"); <BR> bSQL = "Select * FROM 15MinuteDataHor"; <BR> oldDA = new OleDbDataAdapter(bSQL, oldConn);<BR> oldCB = new OleDbCommandBuilder(oldDA);<BR> oldConn.Open();<BR><BR> myRS = new DataSet();<BR> oldDA.Fill(myRS, "15MinuteDataHor");<BR> <BR> <BR> //Modify data<BR> MessageBox.Show(newRS.Tables[0].TableName);<BR> <BR> DataTable dtOLD = myRS.Tables[0];<BR> DataRow newROW;<BR> <BR> foreach(DataRow myRow in dtOLD.Rows)<BR> {<BR> foreach(DataColumn myCol in dtOLD.Columns) <BR> { <BR> if (myCol.Ordinal &#062; 2)<BR> {<BR> newROW = newRS.Tables["15MinuteDataVer"].NewRow();<BR> newROW["AccountID"] = myRow["AccountID"];<BR> newROW["ZipCode"] = myRow["ZipCode"];<BR> <BR> if (myCol.ColumnName == "24:00")<BR> {<BR> newROW["DateTime"] = Convert.ToDateTime(Convert.ToDateTime(myRow["Date"]).AddDays(1).ToShortDateString() + " " + "0:00");<BR> } <BR> else<BR> {<BR> newROW["DateTime"] = Convert.ToDateTime(Convert.ToDateTime(myRow["Date"]).ToShortDateString() + " " + myCol.ColumnName);<BR> } <BR> newROW["Temp"] = myRow[myCol];<BR> newRS.Tables["15MinuteDataVer"].Rows.Add(newROW);<BR> }<BR> }<BR> } <BR> newDA.Update(newRS, "15MinuteDataVer"); <BR> //newRS.AcceptChanges();<BR> <BR> oldConn.Close(); <BR> newConn.Close();<BR> MessageBox.Show("It works too");<BR> }<BR> }<BR>_____________________________________________ ___________________<BR><BR>I copied these items from the data tree in "Locals" section using Visual Studio .NET.<BR><BR><BR>- $exception {System.Data.OleDb.OleDbException} System.Data.OleDb.OleDbException<BR><BR>- System.Runtime.InteropServices.ExternalException {System.Data.OleDb.OleDbException} System.Runtime.InteropServices.ExternalException<B R><BR>- System.SystemException {"Syntax error in INSERT INTO statement."} System.SystemException<BR><BR>- System.Exception {"Syntax error in INSERT INTO statement." } System.Exception<BR><BR>- System.Object {System.Data.OleDb.OleDbException} System.Object<BR><BR>- Source "Microsoft JET Database Engine" string<BR><BR>- StackTrace " at System.Data.Common.DbDataAdapter.Update(DataRow[] dataRows, DataTableMapping tableMapping)
    at System.Data.Common.DbDataAdapter.Update(DataSet dataSet, String srcTable)
    at Invensys.Form1.cmdRun_Click(Object sender, EventArgs e) in c:\my documents\visual studio projects\invensys\form1.cs:line 144
    at System.Windows.Forms.Control.OnClick(EventArgs e)
    at System.Windows.Forms.Button.OnClick(EventArgs e)
    at System.Windows.Forms.Button.OnMouseUp(MouseEventAr gs mevent)
    at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
    at System.Windows.Forms.Control.WndProc(Message& m)
    at System.Windows.Forms.ButtonBase.WndProc(Message& m)
    at System.Windows.Forms.Button.WndProc(Message& m)
    at System.Windows.Forms.ControlNativeWindow.OnMessage (Message& m)
    at System.Windows.Forms.ControlNativeWindow.WndProc(M essage& m)
    at System.Windows.Forms.NativeWindow.DebuggableCallba ck(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
    at System.Windows.Forms.UnsafeNativeMethods.DispatchM essageW(MSG& msg)
    at System.Windows.Forms.ComponentManager.System.Windo ws.Forms.UnsafeNativeMethods+IMsoComponentManager. FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
    at System.Windows.Forms.ThreadContext.RunMessageLoopI nner(Int32 reason, ApplicationContext context)
    at System.Windows.Forms.ThreadContext.RunMessageLoop( Int32 reason, ApplicationContext context)
    at System.Windows.Forms.Application.Run(Form mainForm)
    at Invensys.Form1.Main() in c:\my documents\visual studio projects\invensys\form1.cs:line 85" string<BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts