列数与值计数不匹配

时间:2014-03-15 18:24:55

标签: mysql sql vb.net runtime-error

任何人都可以看到为什么这个SQL字符串会引发“列计数与值计数不匹配”错误?

    SQL = ("INSERT INTO partners_customers(account_name,address1,city,postcode,parent_partners_acc,parent_partners_id) _
    VALUES ('" & newcustname.Text & "','" & newcustaddress.Text & "','" & newcustcity.Text & "," & newcustpostcode.Text & "," & Home.activeuser & "," & Home.activeuserid & "'); SELECT LAST_INSERT_ID()")

据我所知,它有6列和6个值。

它使我疯了:(

谢谢!

2 个答案:

答案 0 :(得分:2)

在最后3个值中,您缺少单引号。格式化代码可帮助您找到以下类型的问题:

SQL = ("
INSERT INTO partners_customers (
    account_name,
    address1,
    city,
    postcode,
    parent_partners_acc,
    parent_partners_id
) _
VALUES
    (
        '" & newcustname. TEXT & "',
        '" & newcustaddress. TEXT & "',
        '" & newcustcity. TEXT & "',
        '" & newcustpostcode. TEXT & "',
        '" & Home.activeuser & "',
        '" & Home.activeuserid & "'
    );

SELECT
    LAST_INSERT_ID()
");

答案 1 :(得分:1)

您缺少至少一个单引号:  可能更多,取决于其他列的数据类型     SQL =(" INSERT INTO partners_customers(account_name,address1,city,postcode,parent_partners_acc,parent_partners_id)_         价值观('"& newcustname.Text&"''"& newcustaddress.Text&"', '"& newcustcity.Text&"',"& newcustpostcode.Text&","& Home.activeuser& ;","& Home.activeuserid&"'); SELECT LAST_INSERT_ID()")