将SQL DATA插入VB数据库

时间:2014-03-04 08:19:17

标签: mysql sql vb.net

对不起我刚开始使用VB的NOOB问题。我终于设法将我的程序与我的phpmyadmin帐户连接,但现在我遇到了这个小问题。

我正在尝试将用户输入表单的数据输入到db表中。 我的语法错了。我正在做以下事情:

Dim SQLStatment As String = "INSERT INTO students(Title, Initial, Surname, Address, City, Country, Postcode) VALUES('" & vtital & vinital & surname & vstreet & vcity & vcountry & vpcode '")"

如果有人能够如此友好地给我一个关于如何使用vb.net将多个可变数据输入数据库的简要说明,那将非常感激。

2 个答案:

答案 0 :(得分:1)

您忘记了分隔符

应该是这样的..

Dim SQLStatment As String = "INSERT INTO students(Title, Initial, Surname, Address, City, Country, Postcode) VALUES('" & vtital & "','" & vinital & "','" & surname & "','" & vstreet & "','" & vcity & "','" & vcountry & "','" & vpcode & "')"

稍后..使用参数化..

答案 1 :(得分:0)

这应该有效:

Dim SQLStatment As String = String.Format("INSERT INTO students(Title, Initial, Surname, Address, City, Country, Postcode) VALUES('{0}','{1}','{2}','{3}','{4}','{5}','{6}')",
vtital, 
vinital,
surname,
vstreet,
vcity,
vcountry,
vpcode)
相关问题