我试图在我的用户表(SQL Server Compact 3.5)中插入一行。这是我的查询(LastName,FirstName和UserPassword是NVARCHAR,IsActive是BIT):
INSERT INTO Users (LastName, FirstName, IsActive, UserPassword) VALUES ('J', 'R', 1, 'T')
我将其转换为C#中的以下代码块:
string returnQuery = "INSERT INTO Users (LastName, FirstName, IsActive, UserPassword)"
+ "VALUES(" + "'" + "@LastName" + "', '" + "@FirstName" + "', @IsActive" + ",'" + "@UserPassword" + "'";
SqlCeCommand returnQueryCommand =
new SqlCeCommand(returnQuery, connection) { CommandType = CommandType.Text };
returnQueryCommand.Parameters.AddWithValue("@LastName", newUser.LastName);
returnQueryCommand.Parameters.AddWithValue("@FirstName", newUser.FirstName);
returnQueryCommand.Parameters.AddWithValue("@IsActive", newUser.IsActive);
returnQueryCommand.Parameters.AddWithValue("@UserPassword", newUser.UserPassword);
运行代码时出现解析错误。但是,当我直接通过CompactView运行查询时,行插入就好了。
我在另一个方法中执行了查询(我从这个方法返回SqlCeCommand)。
思想?
答案 0 :(得分:1)
在值
后缺少关闭括号答案 1 :(得分:0)
你的代码似乎缺少一个关闭的括号来关闭" VALUES"数据
>>> import requests
>>> page = requests.get('http://store.nike.com/us/en_us/pw/mens-clothing/1mdZ7pu?ipp=120').content