【发布时间】:2016-04-07 15:31:24
【问题描述】:
我得到错误:
')' 附近的语法不正确。
代码:
string connetionString = null;
SqlConnection connection;
SqlCommand command;
SqlDataAdapter adapter = new SqlDataAdapter();
DataSet ds = new DataSet();
XmlReader xmlFile;
string sql = null;
connetionString = "Data Source=tsrv2062;Initial Catalog=Bums;User ID=USERNAME;Password=PASSWORD";
connection = new SqlConnection(connetionString);
xmlFile = XmlReader.Create("navetout.xml", new XmlReaderSettings());
ds.ReadXml(xmlFile);
connection.Open();
SqlCommand command1 = new SqlCommand("INSERT INTO Seamen(PersonalIdentityNumber) VALUES (@PersonalIdentityNumber))", connection);
foreach (var P in PersonalIdentityNumber)
{
command1.Parameters.Clear();
command1.Parameters.AddWithValue("@PersonalIdentityNumber", P);
command1.ExecuteNonQuery();
}
connection.Close();
Console.WriteLine("Done");
我在运行时收到此错误,所以不知道它发生在哪里,我只知道它发生在上面的代码中。谁能看出问题出在哪里?
【问题讨论】:
-
values(@PersonalIdentityNumber))你有一个额外的) -
在 sqlcommand 中有一个额外的
) -
删除最后一个
) -
人们对你的问题投了反对票,因为你没有提到这是一个 SqlException。通常,在提问时提供完整的异常详细信息是一个好主意。
i get error没有太多细节。还要确保您没有将密码和用户名等硬核细节放入代码示例中。请务必在询问之前将其删除。 (我为你做了这个) -
我投了反对票,因为这个问题“没有用”(如果你将光标悬停在反对票按钮上,这是反对票的原因之一),我也投票结束了这个问题,因为它是“一个简单的印刷错误”(关闭的内置原因之一)。
标签: c# sql-server