winform 数据库插入问题 cmd没执行,加上cmd.ExecuteNonQuery(); 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 郁闷,你的代码根本就没有保存啊。要害cmd.ExeNoQuerry() 加上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() OleDbCommand cmd = new OleDbCommand("insert into score(username,score,date) values('" + un + "','" + fs + "',#" + time + "#)", obj); Access里面时间用#包含起来 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 ("添加失败!"); }后来我换成这样就可以了 回复6楼:忘记赋代码了,在把时间赋值给label6的时候 就已经把时间转换成字符串了 private void timer1_Tick(object sender, EventArgs e) { label6.Text = System.DateTime.Now.ToString(); } 寫這類語句時可以分開寫,這樣錯誤可能會少些,熟練了就可以用最簡便的方法寫了:OleDbCommand cmd = new OleDbCommand();cmd.Connection=obj;...sql=("insert into score Values('" + un + "','" + fs + "','" + time + "');int i= cmd.ExecuteNonQuery(); cmd没执行,加上 cmd.ExecuteNonQuery();就OK了 1.ExecuteNonQuery();2.调试看看SQL语句是否有错,拷贝出来到查询分析器里去看看。我觉得有错。而且我碰到类似的问题先确定SQL没问题再做别的..访问我的博客 程序员日记 http://www.ideaext.com C#程序题,快,急 如何获取照片的拍照时间? GridView 某行 某列的"名称"来取值 关于ImageList添加图片的问题 如何得到DataGridView的列标题高度 如何利用反射得到的对象 调用基类的方法 asp.net中的SESSION 对应的是哪个类 webform问题?解决100分 师兄师姐帮帮忙!!!如何在网格控件的每一行的行头加一个命令按钮? 请问如何获得本地的ip? 求资料 C# 调用 C++ DLL 的问题 Void * 怎么转换
要害cmd.ExeNoQuerry()
具体如下:
未处理 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()
Access里面时间用#包含起来
{
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 ("添加失败!"); }
后来我换成这样就可以了
private void timer1_Tick(object sender, EventArgs e)
{
label6.Text = System.DateTime.Now.ToString();
}
寫這類語句時可以分開寫,這樣錯誤可能會少些,熟練了就可以用最簡便的方法寫了:
OleDbCommand cmd = new OleDbCommand();
cmd.Connection=obj;...
sql=("insert into score Values('" + un + "','" + fs + "','" + time + "');
int i= cmd.ExecuteNonQuery();
cmd没执行,加上
cmd.ExecuteNonQuery();
就OK了
2.调试看看SQL语句是否有错,拷贝出来到查询分析器里去看看。我觉得有错。而且我碰到类似的问题先确定SQL没问题再做别的..访问我的博客 程序员日记 http://www.ideaext.com