class User
{
public static int Insert() {
OleDbParameter[] o = new OleDbParameter[2];
o[0] = new OleDbParameter("@name", OleDbType.VarChar);
o[0].Value = "飞机";
o[1] = new OleDbParameter("@pwd", OleDbType.VarChar);
o[1].Value = "fjklsdj"; string connstr = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\DataBase\GoodsManage.mdb;Persist Security Info=True";
OleDbConnection conn = new OleDbConnection(connstr);
conn.Open();
OleDbCommand gx = new OleDbCommand("insert into User([Myname],[Pwd]) values('dd','dsfs');", conn);
//foreach (OleDbParameter add in o)
//gx.Parameters.Add(add);
int t = gx.ExecuteNonQuery();
if (t > 0)
{
return 1;
}
else
{
return 0;
}
}
}这是我写的一个小应用程序中的一个类,由于是桌面应用程序,规模较少,所以就用Access+C#了,结果刚开始编写数据库操作的类的时候就老遇到
未处理 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()
在 GoodsManage.BaseClass.User.Insert() 位置 F:\projects\GoodsManage\GoodsManage\BaseClass\User.cs:行号 24
在 GoodsManage.Form1.Form1_Load(Object sender, EventArgs e) 位置 F:\projects\GoodsManage\GoodsManage\Form1.cs:行号 37
在 System.Windows.Forms.Form.OnLoad(EventArgs e)
在 System.Windows.Forms.Form.OnCreateControl()
在 System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
在 System.Windows.Forms.Control.CreateControl()
在 System.Windows.Forms.Control.WmShowWindow(Message& m)
在 System.Windows.Forms.Control.WndProc(Message& m)
在 System.Windows.Forms.ScrollableControl.WndProc(Message& m)
在 System.Windows.Forms.ContainerControl.WndProc(Message& m)
在 System.Windows.Forms.Form.WmShowWindow(Message& m)
在 System.Windows.Forms.Form.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.SafeNativeMethods.ShowWindow(HandleRef hWnd, Int32 nCmdShow)
在 System.Windows.Forms.Control.SetVisibleCore(Boolean value)
在 System.Windows.Forms.Form.SetVisibleCore(Boolean value)
在 System.Windows.Forms.Control.set_Visible(Boolean value)
在 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)
在 GoodsManage.Program.Main() 位置 F:\projects\GoodsManage\GoodsManage\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()最后我索性不加参数,也不用数据库处理类DBAcess类,直接尝试加数据,居然还是报错,我实在没办法了,到网上找了很久,说是用了Access的保留关键字,但我很明显没有啊,这到底怎么回事啊,求求那位大虾救救我吧,我实在不想用SQL SERVER2005,因为那个打包很麻烦的,如果解决不了,至少告诉如果用SQL SERVER2005应该怎么打包,
谢谢了各位
{
public static int Insert() {
OleDbParameter[] o = new OleDbParameter[2];
o[0] = new OleDbParameter("@name", OleDbType.VarChar);
o[0].Value = "飞机";
o[1] = new OleDbParameter("@pwd", OleDbType.VarChar);
o[1].Value = "fjklsdj"; string connstr = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\DataBase\GoodsManage.mdb;Persist Security Info=True";
OleDbConnection conn = new OleDbConnection(connstr);
conn.Open();
OleDbCommand gx = new OleDbCommand("insert into User([Myname],[Pwd]) values('dd','dsfs');", conn);
//foreach (OleDbParameter add in o)
//gx.Parameters.Add(add);
int t = gx.ExecuteNonQuery();
if (t > 0)
{
return 1;
}
else
{
return 0;
}
}
}这是我写的一个小应用程序中的一个类,由于是桌面应用程序,规模较少,所以就用Access+C#了,结果刚开始编写数据库操作的类的时候就老遇到
未处理 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()
在 GoodsManage.BaseClass.User.Insert() 位置 F:\projects\GoodsManage\GoodsManage\BaseClass\User.cs:行号 24
在 GoodsManage.Form1.Form1_Load(Object sender, EventArgs e) 位置 F:\projects\GoodsManage\GoodsManage\Form1.cs:行号 37
在 System.Windows.Forms.Form.OnLoad(EventArgs e)
在 System.Windows.Forms.Form.OnCreateControl()
在 System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
在 System.Windows.Forms.Control.CreateControl()
在 System.Windows.Forms.Control.WmShowWindow(Message& m)
在 System.Windows.Forms.Control.WndProc(Message& m)
在 System.Windows.Forms.ScrollableControl.WndProc(Message& m)
在 System.Windows.Forms.ContainerControl.WndProc(Message& m)
在 System.Windows.Forms.Form.WmShowWindow(Message& m)
在 System.Windows.Forms.Form.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.SafeNativeMethods.ShowWindow(HandleRef hWnd, Int32 nCmdShow)
在 System.Windows.Forms.Control.SetVisibleCore(Boolean value)
在 System.Windows.Forms.Form.SetVisibleCore(Boolean value)
在 System.Windows.Forms.Control.set_Visible(Boolean value)
在 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)
在 GoodsManage.Program.Main() 位置 F:\projects\GoodsManage\GoodsManage\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()最后我索性不加参数,也不用数据库处理类DBAcess类,直接尝试加数据,居然还是报错,我实在没办法了,到网上找了很久,说是用了Access的保留关键字,但我很明显没有啊,这到底怎么回事啊,求求那位大虾救救我吧,我实在不想用SQL SERVER2005,因为那个打包很麻烦的,如果解决不了,至少告诉如果用SQL SERVER2005应该怎么打包,
谢谢了各位
OleDbCommand gx = new OleDbCommand("insert into User([Myname],[Pwd]) values('dd','dsfs');", conn);
检查一下你的语句和你的表有没有问题,应该能够搞定吧.
select 'dd' as Myname,'dsfs' as Pwd
insert into [User]([Myname],[Pwd]) values('dd','dsfs') 试试
[/Quote]
应该是用单引号,我现在重新建了一个项目,全部重新来,结果就没问题了,真郁闷,不过我到目前为止只是用select成功了,其他的还不知道呢