将空值从文本框插入表 [英] inserting null values from text box to table

查看:73
本文介绍了将空值从文本框插入表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将文本框的空值插入表中。以下查询有效,但当我将文本框留空时,它给出了错误条件表达式中数据类型不匹配

我检查了属性表下的验证规则是空白的,并且必填字段设置为否ms访问表。

I am trying to insert null value of a text box into table. The below query works but when I leave a text box empty it gives me error " data type mismatch in criteria expression"
I have checked validation rule under property sheet is blank and required field is set to no in ms access table.

"insert into " & ComboBox1.SelectedValue & " (a,b)values ('" & TextBox1.Text & "','" & TextBox2.Text & "')" 







我试过这个,它给了我错误 - INSERT INTO语句中的语法错误。






I have tried this , it gives me error - Syntax error in INSERT INTO statement.

"insert into " & ComboBox1.SelectedValue & " (a,B) DBnull.values ('" & TextBox1.Text & "','" & TextBox2.Text & "')"





有人能告诉我如何在表格中插入文本框的空值吗?

谢谢



can someone tell me how to insert null value of a text box into table?
Thanks

推荐答案

请看我对这个问题的评论。按照公式制定,似乎没有任何意义。



但是,从一开始你的做法就错了。通过串联从UI获取的字符串组成的查询。不仅重复的字符串连接是低效的(因为字符串是不可变的;我是否必须解释为什么它会使重复连接变坏?),但是有更重要的问题:它打开了通向良好的大门已知的漏洞称为 SQL注入



这是它的工作原理: http://xkcd.com/327



你明白了吗?从控件中获取的字符串可以是任何东西,包括......一段SQL代码。



怎么办?只需阅读有关此问题和主要补救措施:参数化语句 http://en.wikipedia.org/ wiki / SQL_injection



使用ADO.NET,使用:http://msdn.microsoft.com/en-us/library/ff648339.aspx



请参阅我过去的答案有更多细节:

在com.ExecuteNonQuery中更新EROR( );

嗨名字没有显示在名称中?



-SA
Please see my comment to the question. As formulated, it does not seems to make any sense.

However, your approach is wrong from the very beginning. The query composed by concatenation with strings taken from UI. Not only repeated string concatenation is inefficient (because strings are immutable; do I have to explain why it makes repeated concatenation bad?), but there is way more important issue: it opens the doors to a well-known exploit called SQL injection.

This is how it works: http://xkcd.com/327.

Are you getting the idea? The string taken from a control can be anything, including… a fragment of SQL code.

What to do? Just read about this problem and the main remedy: parametrized statements: http://en.wikipedia.org/wiki/SQL_injection.

With ADO.NET, use this: http://msdn.microsoft.com/en-us/library/ff648339.aspx.

Please see my past answers for some more detail:
EROR IN UPATE in com.ExecuteNonQuery();,
hi name is not displaying in name?.

—SA


这篇关于将空值从文本框插入表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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