当在 SQL Server Management Studio 中用作查询时,该代码可以正常工作并插入到表中。我是 SQL 新手,因此感谢您提供任何帮助,谢谢。
SQL Server Management Studio 查询:
INSERT INTO Site(
Sub_Company_ID,
Site_Name,
Site_Code,
Site_Address_1,
Site_Address_2,
Site_Address_3,
Site_Address_4,
Site_Postcode,
Site_Email,
Site_Username,
Site_Password,
Site_Order_Budget,
Site_Float,
Site_Managment_Percentage,
Site_Bond_Percentage,
Site_Minimum_Fee)
VALUES(
'01',
'a',
'1',
'c',
'd',
'e',
'f',
'g',
'h',
'i',
'j',
'1',
'2',
'3',
'4',
'5')
但是,当在实际程序中使用时,对于在文本中键入的 site_name 的任何内容,我都会收到异常错误。它说只允许使用常量、表达式或变量——尽管在我的 SQL 语句中使用字符串“a”时我没有这个问题。(这是程序中的一行,我只是想让这里更容易阅读)。
程序代码:
Dim str As String = "INSERT INTO Site(
Sub_Company_ID,
Site_Name,
Site_Code,
Site_Address_1,
Site_Address_2,
Site_Address_3,
Site_Address_4,
Site_Postcode,
Site_Email,
Site_Username,
Site_Password,
Site_Order_Budget,
Site_Float,
Site_Managment_Percentage,
Site_Bond_Percentage,
Site_Minimum_Fee)
VALUES("
& lstSubCompany.SelectedValue & ","
& txtSiteName.Text & ","
& txtSiteCode.Text & ","
& txtAddress1.Text & ","
& txtAddress2.Text & ","
& txtAddress3.Text & ","
& txtAddress4.Text & ","
& txtPostcode.Text & ","
& txtEmail.Text & ","
& txtUsername.Text & ","
& txtPassword.Text & ","
& txtOrderBudget.Text & ","
& txtFloat.Text & ","
& txtManagmentFee.Text & ","
& txtBond.Text & ","
& txtMinimumFee.Text & ")"