cmd没执行,加上
cmd.ExecuteNonQuery();

解决方案 »

  1.   

    郁闷,你的代码根本就没有保存啊。
    要害cmd.ExeNoQuerry()
      

  2.   

    加上cmd.ExecuteNonQuery(); 后,按下按钮 提示未处理OleDbexception,insert into语句语法错误
    具体如下:
    未处理 System.Data.OleDb.OleDbException
      Message="INSERT INTO 语句的语法错误。"
      Source="Microsoft JET Database Engine"
      ErrorCode=-2147217900
      StackTrace:
           在 System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingleResult(tagDBPARAMS dbParams, Object& executeResult)
           在 System.Data.OleDb.OleDbCommand.ExecuteCommandText(Object& executeResult)
           在 System.Data.OleDb.OleDbCommand.ExecuteCommand(CommandBehavior behavior, Object& executeResult)
           在 System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior behavior, String method)
           在 System.Data.OleDb.OleDbCommand.ExecuteNonQuery()
           在 Tetris2.FrmTetris.label2_Click(Object sender, EventArgs e) 位置 G:\bishe\Tetris2\Tetris2\FrmTetris.cs:行号 240
           在 System.Windows.Forms.Control.OnClick(EventArgs e)
           在 System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
           在 System.Windows.Forms.Control.WndProc(Message& m)
           在 System.Windows.Forms.Label.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)
           在 Tetris2.Program.Main() 位置 G:\bishe\Tetris2\Tetris2\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()
      

  3.   

      OleDbCommand cmd = new OleDbCommand("insert into score(username,score,date) values('" + un  + "','" + fs + "',#" + time + "#)", obj); 
     Access里面时间用#包含起来
      

  4.   

    private void label2_Click(object sender, EventArgs e)
            {   
                string un = label1.Text;
                string fs = p.Score.ToString();
                string time = label6.Text;
                string strcon = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|score.mdb";
                OleDbConnection obj = new OleDbConnection(strcon);
                obj.Open();
                OleDbCommand cmd = new OleDbCommand("insert into score Values('" + un + "','" + fs + "','" + time + "')", obj);
                int count = cmd.ExecuteNonQuery();
                if (count >0)
                {
                    MessageBox .Show ("添加成功!");            }
                else 
                {MessageBox .Show ("添加失败!");            }
    后来我换成这样就可以了 
      

  5.   

    回复6楼:忘记赋代码了,在把时间赋值给label6的时候 就已经把时间转换成字符串了
     private void timer1_Tick(object sender, EventArgs e)
            {
                label6.Text = System.DateTime.Now.ToString();
            }
      

  6.   


      寫這類語句時可以分開寫,這樣錯誤可能會少些,熟練了就可以用最簡便的方法寫了:
    OleDbCommand cmd = new OleDbCommand();
    cmd.Connection=obj;...
    sql=("insert into score Values('" + un + "','" + fs + "','" + time + "');
    int i= cmd.ExecuteNonQuery(); 
      

  7.   


    cmd没执行,加上 
    cmd.ExecuteNonQuery();
    就OK了
      

  8.   

    1.ExecuteNonQuery();
    2.调试看看SQL语句是否有错,拷贝出来到查询分析器里去看看。我觉得有错。而且我碰到类似的问题先确定SQL没问题再做别的..访问我的博客 程序员日记 http://www.ideaext.com