【发布时间】:2019-04-17 06:06:03
【问题描述】:
使用下面的语句,查询的 @table 部分出现异常。可以这样使用数据表插入SQLite吗?
DataTable table = new DataTable();
table.Columns.Add("Path", typeof(string));
table.Columns.Add("StopName", typeof(string));
table.Columns.Add("Latitude", typeof(string));
table.Columns.Add("Longitude", typeof(string));
foreach (Result result in tempResults)
{
table.Rows.Add(result.Path, result.StopName, result.Latitude, result.Longitude);
}
SQLiteCommand command = new SQLiteCommand("INSERT OR REPLACE INTO ZZ_DBA_Stop (Path, StopName, Latitude, Longitude) SELECT Path, StopName, Latitude, Longitude FROM @table", connection) { CommandTimeout = 3600, CommandType = CommandType.Text };
command.Parameters.AddWithValue("@table", table);
await command.ExecuteNonQueryAsync();
【问题讨论】:
-
否,FROM 参数中不能使用参数。无论如何,您不能传递 DataTable 并希望将其用于插入数据库表中。