private void ButtonUpdate(object sender, EventArgs e)
        {
            string updCmd = "update country set code=@code,shortname=@shortname,fullname=@fullname";
            objOleDbDataAdapter.UpdateCommand = new OleDbCommand(updCmd, conn);   //出错地方            objOleDbParameter = objOleDbDataAdapter.UpdateCommand.Parameters.Add("@code", OleDbType.Char);
            objOleDbParameter.SourceColumn = "code";
            objOleDbParameter.SourceVersion = DataRowVersion.Current;            objOleDbParameter = objOleDbDataAdapter.UpdateCommand.Parameters.Add("@shortname", OleDbType.VarChar);
            objOleDbParameter.SourceColumn = "shortname";
            objOleDbParameter.SourceVersion = DataRowVersion.Current;            objOleDbParameter = objOleDbDataAdapter.UpdateCommand.Parameters.Add("@shortname", OleDbType.VarChar);
            objOleDbParameter.SourceColumn = "shortname";
            objOleDbParameter.SourceVersion = DataRowVersion.Current;            DialogResult objDialogResult = MessageBox.Show("确定要保存吗?", "确定", MessageBoxButtons.YesNo, MessageBoxIcon.Question);            try
            {
                if (objDialogResult == DialogResult.Yes)
                {
                    objOleDbDataAdapter.Update(objDataSet, "country");
                    MessageBox.Show("修改成功");
                }
                else
                {
                    MessageBox.Show("修改失败");
                }
            }
            catch (OleDbException ex)
            {
                MessageBox.Show(ex.Message);
            }
        }对数据进行update中出现的

解决方案 »

  1.   

    未处理 System.NullReferenceException
      Message="未将对象引用设置到对象的实例。"
      Source="适配器"
      StackTrace:
           在 适配器.Form1.ButtonUpdate(Object sender, EventArgs e) 位置 E:\2.24\适配器\适配器\Form1.cs:行号 85
           在 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)
           在 适配器.Program.Main() 位置 E:\2.24\适配器\适配器\Program.cs:行号 17
           在 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()
      

  2.   

    objOleDbDataAdapter
    或者conn没有new过吧