Ms Access Insert问题 [英] Ms Access Insert Problem

查看:72
本文介绍了Ms Access Insert问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的所有我使用c#服务器端代码使用Window窗体。



使用访问数据库。我在此应用程序配置中添加应用程序配置文件我创建此连接

Dear All I m Using Window forms using c# server side code .

using access database . i add app config file in this app config i cretae this connection

<add name="ROMS.Properties.Settings.DBRomsConnectionString" connectionstring="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\Resources\DBRoms.mdb;Persist Security Info=True" providerName="System.Data.OleDb" />



比我直接调用form.cs文件


Than i call this directly form.cs file

OleDbConnection con = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Users\USER\Desktop\ROMS\ROMS\ROMS\Resources\DBRoms.mdb");





i donot知道如何调用此连接字符串。





i插入点有问题: -



i donot know how to call this connection string .


i get problem to insert point : -

query = "INSERT INTO Employee(EmployeeID,LoginID,Department,Designation,FinYear1,FinYear2,Password,) VALUES('" + txtEmployeeId.Text + "','" + txtLoginId.Text + "','" + CBEmployeeDepartment.SelectedItem.ToString() + "','" + CBEmployeeDesignation.SelectedItem.ToString() + "','" + CBFinYear1.SelectedItem.ToString() + "','" + CBFinYear2.SelectedItem.ToString() + "','" + txtEmployeePassword.Text + "')";
con.Open();
cmd = new OleDbCommand(query, con);
cmd.ExecuteNonQuery();
con.Close();





我在Execute nonquery中收到错误。



所有数据字段值都是文本。



I get error in Execute nonquery .

all data field value is text .

推荐答案

删除最后一个逗号来自 INSERT 查询

Remove the last comma from INSERT query
query = "INSERT INTO Employee(EmployeeID,LoginID,Department,Designation,FinYear1,FinYear2,Password,) VALUES('" + 



编辑


不要使用关键字/保留字,如密码。您必须为该列添加方括号,如下所示,但我不推荐。您应该重命名列名称(如Emp_Password)



[ 密码 ]


EDIT


Don't use keywords/reserved words like Password. You have to add square brackets for that column like below but I wont recommend that. You should rename the column name( like Emp_Password )

[Password]


这篇关于Ms Access Insert问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆