“插入到语句中的语法错误"; [英] "Syntax error in Insert Into Statement"

查看:88
本文介绍了“插入到语句中的语法错误";的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

当我填写所有文本框,然后单击成功插入的保存按钮数据时.但是,当我将一个或多个文本框留空时,则出现在插入语句中出现语法错误".我该怎么解决?.
表(Ms-Access).

代码

hi all,

when i fill all textboxes and then click on save button data inserted successfully. but when i leave one or more textbox blank then "Syntax error in Insert Into Statement". how can i solve?.
Table (Ms-Access).

Code

c.Exec("insert into donor(id,name,address,con1,con2,dob,fdd,amt)values(" & TextBox1.Text & ",'" & ComboBox1.Text & "','" & TextBox3.Text & "','" & TextBox4.Text & "','" & TextBox5.Text & "','" & DateTimePicker1.Value.Date & "','" & TextBox6.Text & "'," & TextBox2.Text & ")")
        c.StdMsg("Record Saved successfully.")





推荐答案

如果您进行了调试,则几乎不需要5分钟.

示例:
假设我没有填写Textbox1,Textbox5& Textbox2.

我形成的Insert语句是:
If you would had debugged, it would had taken hardly 5 min.

Example:
Assume I do not fill Textbox1, Textbox5 & Textbox2.

My Insert statement formed is:
Insert into donor(id,name,address,con1,con2,dob,fdd,amt)values(,TextBox3_Text,TextBox4_Text,, DateTimePicker1_Value_Date,,)



看到什么了吗?只需直接在数据库上运行上述查询,然后亲自查看即可.



Saw anything? Just run the above query directly on database and see for yourself.


我相信您会发现参数非常有用.几个例子:
- http://support.microsoft.com/kb/181782 [ http://support.microsoft.com/kb/142938 [
I believe you will find parameters very useful. Few examples:
- http://support.microsoft.com/kb/181782[^]
- http://support.microsoft.com/kb/142938[^]


解决此问题的最简单方法是将插入语句之前的验证块,如果未提供文本项,则在其中初始化文本项的值,然后继续插入语句.

其次,我建议您使用Mika提到的Parameters选项.
看看下面的链接

MS访问参数 [
The simplest way to get around this problem would be to put a validation block before the Insert into statement where you initialise a value to the text items if they are not provided and then continue with the insert into statement.

Secondly i would suggest you make use of Parameters option as Mika has mentioned.
Take a look at the below link

MS Access Parameters[^]


这篇关于“插入到语句中的语法错误";的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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