在vb.net和ms访问中的insert语句中获取错误 [英] Getting error in insert statement in vb.net and ms access

查看:117
本文介绍了在vb.net和ms访问中的insert语句中获取错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



下面是我的代码快照,我想在Inwards表中插入值,我已经存储了所有变量,如命令,con在模块中。我没有收到任何错误,但是当我调试时,我得到异常消息INSERT INTO语句中的语法错误。 PLZ帮助我,



Hi
below is my code snapshot where i wanted to insert values in Inwards table, I have stores all variables like command,con in module. I am not getting any error but when i debugged then i got exception message as "Syntax error in INSERT INTO statement." plz help me,

str = "Insert Into Inwards (SerialNumber,LetterNumber,DateOfEntry,Subject,From,LetterType,AssignedTo,BeltNumber,DateOfIssue) values(" + txtSerialNo.Text.Trim + "," + txtLetterNumber.Text.Trim + ",'" + lblDate.Text.Trim + "','" + txtSubject.Text.Trim + "','" + txtFrom.Text.Trim + "','" + cbType.Text.Trim + "','" + txtAssignedTo.Text.Trim + "','" + txtBeltNumber.Text.Trim + "','" + dtDOI.Text.Trim + "')"
               cmd = New OleDb.OleDbCommand(str, con)
               con.Open()
               cmd.ExecuteNonQuery()
               MsgBox("Inserted Successfully new Inward..")

               'data()
               'clearText()
           Catch ex As Exception

           Finally
               con.Close()

           End Try

推荐答案

如果 DateOfIssu e 字段是日期数据类型,请使用如下查询:

If DateOfIssue field is date data type, please, use query like this:
INSERT INTO Table1 (DateField1)
VALUES(#2013/06/05#) 



for text:


for text:

INSERT INTO Table1 (TextField1)
VALUES('any text') 



的数值:


for numeric values:

INSERT INTO Table1 (NumericField1)
VALUES(1000) 





有一个看这里:

添加,编辑和删除数据(MS Access) [ ^ ]

INSERT INTO Statement(Microsoft Access SQL) [ ^ ]


谷歌的SQL注入攻击,看看为什么你在做什么是如此糟糕。这是一个巨大的安全风险。



然后谷歌的VB.NET SQL参数化查询如何解决它。



是的,您可以在Access数据库中创建一个AutoNumber列。如果您在Access中创建数据库,那么当您为该列选择字段类型时,它就会一直盯着您。
Google for "SQL Injection Attack" to see why what you''re doing is so bad. It''s a HUGE security risk.

Then Google for "VB.NET SQL Parameterized Queries" on how to fix it.

Yes, you can make an AutoNumber column in an Access database. If you made the database in Access it would have been staring you right in the face when you picked a field type for the column.


这篇关于在vb.net和ms访问中的insert语句中获取错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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