插入语句附近的错误语法 [英] Incorect syntex near insert statment

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

问题描述

我有多个文本框和一个提交按钮

单击它会在文本框中获取数据并将其插入数据库.

我正在检查文本是否不是",然后插入textbox.text,否则这里没有代码示例:

I have multiple text box and a submit button

on click it take data in text box and insert them to database.

I''m checking if text is not "" then insert textbox.text else nothing here is code sample:

Insert into tablename(col1, col2, col3) values( 

& if not textboxone.text="" 

,'textboxone.text'

else

''

.
.
.
)

推荐答案

使用参数化查询:
Using con As New SqlConnection(strConnection)
	con.Open()
	Using cmd As New SqlCommand("INSERT INTO MyTable(Id, MyText) VALUES (@ID, @MT)", con)
		cmd.Parameters.AddWithValue("@ID", Id)
		cmd.Parameters.AddWithValue("@MT", If(myTextBox.Text = "", DirectCast(DBNull.Value, Object), DirectCast(myTextBox.Text, Object)))
		cmd.ExecuteNonQuery()
	End Using
End Using


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

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