我的 SQL 语句有问题
Threads
-------
ThreadID
UsersID
Date
ThreadTitle
ThreadParagraph
ThreadClosed
Topics
-----
TopicsID
Theme
Topics
Date
这是我的声明:
StringBuilder insertCommand = new StringBuilder();
insertCommand.Append("DECLARE @TopicsID int");
insertCommand.Append("INSERT INTO Topics(Theme,Topics,Date)");
insertCommand.Append("VALUES(@topic,@subTopic,GETDATE())");
insertCommand.Append("SET @TopicsID = SCOPE_IDENTITY()");
insertCommand.Append("INSERT INTO Threads(UsersID,TopicsID,Date,ThreadTitle,ThreadParagraph,ThreadClosed)");
insertCommand.Append("VALUES(@uniqueIdentifier,@TopicsID,GETDATE(),@questionTitle,@questionParagraph,0)");
我明白了:
关键字附近的语法不正确 '进入'。必须声明标量 变量“@TopicsID”。必须声明 标量变量“@TopicsID”。
Threads
-------
ThreadID
UsersID
Date
ThreadTitle
ThreadParagraph
ThreadClosed
Topics
-----
TopicsID
Theme
Topics
Date
Here is my statement:
StringBuilder insertCommand = new StringBuilder();
insertCommand.Append("DECLARE @TopicsID int");
insertCommand.Append("INSERT INTO Topics(Theme,Topics,Date)");
insertCommand.Append("VALUES(@topic,@subTopic,GETDATE())");
insertCommand.Append("SET @TopicsID = SCOPE_IDENTITY()");
insertCommand.Append("INSERT INTO Threads(UsersID,TopicsID,Date,ThreadTitle,ThreadParagraph,ThreadClosed)");
insertCommand.Append("VALUES(@uniqueIdentifier,@TopicsID,GETDATE(),@questionTitle,@questionParagraph,0)");
I get this:
Incorrect syntax near the keyword
'INTO'. Must declare the scalar
variable "@TopicsID". Must declare the
scalar variable "@TopicsID".
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我注意到的第一件事是:
可能需要是:
看起来你在那里有一些额外的单引号。
The first thing I notice is:
might need to be:
It looks like you have some extra single quotes in there.
在
DECLARE @TopicsID int
之后需要一个分号,这将处理“不正确的语法”并声明标量变量。
我相信您需要删除三个
VALUES
周围的单引号。这导致它认为您只提供了一个VALUE
而不是三个。You need a semi-colon after
DECLARE @TopicsID int
That will take care of the "incorrect syntax" and declaring the scalar variable.
And I believe that you need to remove the single quotes around your three
VALUES
. That is causing it to think you have supplied only oneVALUE
instead of three.尝试
insertCommand.AppendLine
SQL 看到
DECLARE @TopicsID intINSERT INTO Topics(Theme,Topics,Date) ...
您需要分隔不同的语句
Try
insertCommand.AppendLine
SQL sees
DECLARE @TopicsID intINSERT INTO Topics(Theme,Topics,Date) ...
You need to separate the distinct statements
最后一行的单引号是错误的 - 它把它全部变成一个字符串:
更改
为
Your single quotes on the last line are wrong - its turning it all onto one string:
Change
to