0

请帮我解决这个更新查询。我完全理解这是多么多余,但我需要它。在用户创建一个仅包含 ID、用户名、密码和 CustomerID 的用户帐户时,我还必须在客户中创建一个记录,但所有内容都为空,并且 User.User_Customer_ID 必须更新为新创建的 Customer.Customer_ID

除了这个讨厌的更新查询,我一切正常。它唯一需要做的就是将 User.User_Customer_ID 更改为 Customer.Customer_ID 我设法将 User.User_ID 记录在一个名为 UserID 的整数中,将 Customer.Customer_ID 记录在一个名为 CustomerID 的整数中 我已经尝试了一百万种不同的方法,但没有成功

这是我尝试过的众多查询之一。

1. UPDATE [User]
   SET User_Customer_ID = Customer.Customer_ID
   FROM Customer
   WHERE [User].User_ID = '16'
   AND Customer.CUstomer_ID = '19'
  ( ? would be the integer UserID and CustomerID )

这是它在 VB 中插入 SQL 命令之前的样子

   UpdateUserCustomerID = "UPDATE [User] SET User_Customer_ID = Customer.Customer_ID FROM Customer WHERE ([User].User_ID ='" & UserID & "' AND Customer.Customer_ID = '" & CustomerID & "')"

访问数据库 / ASP.Net / VB

Table:

Customer:

Customer_ID
Customer_First_Name
Customer_Last_Name
Customer_Street_Address
Customer_City
Customer_State
Customer_Zip
Customer_Email

User:

User_ID
User_UserName
User_Password
User_Customer_ID
4

1 回答 1

2

在我看来,ID 不太可能是文本字段(列),如果它们是数字字段,引号是问题之一。

据我所知,这是:

"UPDATE [User] SET User_Customer_ID = Customer.Customer_ID FROM Customer WHERE ([User].User_ID ='" & UserID & "' AND Customer.Customer_ID = '" & CustomerID & "')"

应该:

"UPDATE [User] SET User_Customer_ID = " & CustomerID _
& " WHERE ([User].User_ID = " & UserID 
于 2012-06-13T12:45:56.040 回答