string DBlocation = "";
            OleDbConnection dbconn = null;
            OleDbDataReader dbreader = null;
            OleDbDataAdapter da=null;
            try
            {
                dbconn = new OleDbConnection(@"provider=microsoft.jet.oledb.4.0; Data Source=D:\SQL.mdb");
                dbconn.Open();
                da = new OleDbDataAdapter(@"select * from Result_OK where Production_NO='123456'", dbconn);
                DataSet ds = new DataSet("Result_OK");
                da.Fill(ds,"Result_OK");
                OleDbCommandBuilder cb = new OleDbCommandBuilder(da);
                da.UpdateCommand = cb.GetUpdateCommand();
                DataRow drx = ds.Tables[0].NewRow();
                drx["TX_AP"]=12;
                //ds.Tables[0].Rows.Add(drx); //在表中追加记录
                da.Update(ds); //更新数据库
                String kx = ds.Tables[0].Rows[0]["TX_AP"].ToString();//读出数据库中的值                
            }
            catch
            {
                MessageBox.Show("chuzuoi");
            }
     String kx = ds.Tables[0].Rows[0]["TX_AP"].ToString()读取里面的至没问题,但是 da.Update(ds); //更新数据库
却一直报错,求大大帮忙看下该如何修改

解决方案 »

  1.   

    去掉catch语句先,看看报什么错
      

  2.   

    它的运行没有进入 catch 的 
      

  3.   

    按照你说的 去掉 catch
      

  4.   

    da.Update(ds, " table_name ");
    缺少更新的表名
      

  5.   

    da.Update(ds, " table_name ");
    缺少更新的表名
      

  6.   

    按照你说的去掉 catch  在 UPdata 那据报错 提示
    updata 无法找到 tablemapping['table']或者datatable“table”.
    可是 如果我把  DataSet ds = new DataSet("Result_OK"); 修改为 DataSet ds = new DataSet(}
     UPdata 不报错了 ,但是数据却为更新进去,小弟 C#新手,请大大指点
      

  7.   

     DataSet ds = new DataSet("Result_OK");
        da.Fill(ds, "Result_OK");
     da.Update(ds,"Result_OK");
    这个时候 不报错  ,但资料却依旧没有更新进入
      

  8.   


    不是查询直接更新的,我是进入查找序号为123456的那条记录,(序号为主索引,原本在里面 TX_AP的值为10,)现在我想能找到123456的那条记录,并且 在TX_AP 写入12
     代码如下 
        dbconn = new OleDbConnection(@"provider=microsoft.jet.oledb.4.0; Data       Source=D:\SQL.mdb");
                    dbconn.Open();
                    da = new OleDbDataAdapter(@"select * from Result_OK where Production_NO='123456'", dbconn);
                    DataSet ds = new DataSet("Result_OK");
                    da.Fill(ds, "Result_OK");
                    OleDbCommandBuilder cb = new OleDbCommandBuilder(da);
                    da.UpdateCommand = cb.GetUpdateCommand();
                    DataRow drx = ds.Tables[0].NewRow();
                    drx["TX_AP"]=12;
                    //ds.Tables[0].Rows.Add(drx); //在表中追加记录
                    da.Update(ds,"Result_OK"); //更新数据库
                    String kx = ds.Tables[0].Rows[0]["TX_AP"].ToString();//读出数据库中的值 
      

  9.   

    有点混乱呢。
    drx是新做成的datarow,没有插入da就直接update,肯定不会对数据库有影响吧。
    LZ的逻辑貌似有问题
      

  10.   

    LZ想做的是更新的话,对查询出来的数据进行编辑再做DB更新就好了吧
    if(ds.Tables[0].Rows.Count()>0)
    {
      ds.Tables[0].Rows[0]["TX_AP"] = "12";
      da.Update(ds,"Result_OK");
    }
      

  11.   


    new SqlCommandBuilder(adapter); //这行你没加
    adapter.Update(dataset
      

  12.   

    我按照你现在的方式修改的 可是报错了,运行部下去da.Update(ds, "Result_OK"); 提示 未处理 System.Data.OleDb.OleDbException
      Message="语法错误 (操作符丢失) 在查询表达式 '((Production_NO = ?) AND ((? = 1 AND Model IS NULL) OR (Model = ?)) AND ((? = 1 AND Data Rate IS NULL) OR (Data Rate = ?)) AND ((? = 1 AND Wavelength IS NULL) OR (Wavelength = ?)) AND ((? = 1 AND Voltage IS NULL) OR (Voltage = ?)) AND ((? = 1 AND Workorde' 中。"
      Source="Microsoft JET Database Engine"
      ErrorCode=-2147217900
      StackTrace:
           在 System.Data.Common.DbDataAdapter.UpdatedRowStatusErrors(RowUpdatedEventArgs rowUpdatedEvent, BatchCommandInfo[] batchCommands, Int32 commandCount)
           在 System.Data.Common.DbDataAdapter.UpdatedRowStatus(RowUpdatedEventArgs rowUpdatedEvent, BatchCommandInfo[] batchCommands, Int32 commandCount)
           在 System.Data.Common.DbDataAdapter.Update(DataRow[] dataRows, DataTableMapping tableMapping)
           在 System.Data.Common.DbDataAdapter.UpdateFromDataTable(DataTable dataTable, DataTableMapping tableMapping)
           在 System.Data.Common.DbDataAdapter.Update(DataSet dataSet, String srcTable)
           在 WindowsFormsApplication1.Form1.button1_Click(Object sender, EventArgs e) 位置 C:\Documents and Settings\chenjp\桌面\WindowsFormsApplication1\WindowsFormsApplication1\Accsec.cs:行号 48
           在 System.Windows.Forms.Control.OnClick(EventArgs e)
           在 System.Windows.Forms.Button.OnClick(EventArgs e)
           在 System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
           在 System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
           在 System.Windows.Forms.Control.WndProc(Message& m)
           在 System.Windows.Forms.ButtonBase.WndProc(Message& m)
           在 System.Windows.Forms.Button.WndProc(Message& m)
           在 System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
           在 System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
           在 System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
           在 System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
           在 System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
           在 System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
           在 System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
           在 System.Windows.Forms.Application.Run(Form mainForm)
           在 WindowsFormsApplication1.Program.Main() 位置 C:\Documents and Settings\chenjp\桌面\WindowsFormsApplication1\WindowsFormsApplication1\Program.cs:行号 18
           在 System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
           在 System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
           在 Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
           在 System.Threading.ThreadHelper.ThreadStart_Context(Object state)
           在 System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
           在 System.Threading.ThreadHelper.ThreadStart()
      InnerException: 
      

  13.   

    我 在调试的时候  12的 双引号去掉了,因为 TX_AP 那个栏位,我设定的存入为数值。纠结啊,你真是好人 ,能告诉我你的 QQ么?