且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

通过vb.net将新行插入到访问表中,但未在表中添加

更新时间:2023-12-06 13:38:52

我会执行以下操作

1.获取动态生成的SQL语句,然后直接在您的Access数据库上运行它,以确保sql字符串中没有错误.即

I would do the following

1. Get the SQL Statement that is dynamically generated and run it directly on your access database to make sure there is no errors in your sql string. i.e.

INSERT INTO tbl_Mine ( MINE_NAME, Mojaveze_Bahrebardari_No, Mojaveze_Bahrebardari_Date, Geo_Location, Personel_No, Capacity) values ("fred","Test",15/08/2011,"Worcester",12345,1)



2.我将更改您的SQL语句以使用参数化查询.

使用MS Access进行参数化查询 [ ^ ]



2. I would change your SQL Statement to use parameterized queries.

Parameterized queries with MS Access[^]


要检查的几件事:

  • Lo_cmd.ExecuteNonQery上设置一个断点,这将返回什么.返回的数字是受影响的行数.如果它为0,则不会插入任何内容.
  • 在您的catch块中,您似乎正在从连接中收集错误.是否还会从命令中收集错误?调试代码时,请检查代码是否未真正到达catch块,并可能错误地返回0.
  • 您使用的数据库文件在哪里.它是在静态位置还是包含在您的项目中.可能是因为在您运行项目时,调试或发布目录中的数据库文件被项目附带的初始版本覆盖.
Few things to check:

  • put a breakpoint to Lo_cmd.ExecuteNonQery, what does this return. The returned number is the number of rows affected. If it''s 0 nothing is inserted.
  • in your catch block, it looks like you''re gathering the errors from the connection. Does that gather errors also from the command? When debugging the code check that the code isn''t actually hitting the catch block and possibly returning 0 erroneously.
  • where is the database file you use. Is it in a static location or is it included in your project. Could it be that when you run the project the database file in debug or release directory gets overwritten with the initial version included with the project.
INSERT INTO tbl_Mine 
( MINE_NAME, Mojaveze_Bahrebardari_No, Mojaveze_Bahrebardari_Date, Geo_Location, Personel_No, Capacity) 
values ('Some's name',...


肯定会导致错误.


That would certainly cause an error.