gpt4 book ai didi

c# - 运行 2 个单独的查询但获取参数不应为空错误

转载 作者:行者123 更新时间:2023-11-29 23:06:56 25 4
gpt4 key购买 nike

我尝试运行以下 2 个单独的查询,但不断收到以下错误消息:

enter image description here

我查看了数据库,第一个查询成功(因此参数不为空),但在 cmd.ExecuteNonQuery(); 处失败。在for (var i = 0; i < _waypointList.Count; i++) { ... }

这有什么原因吗?

        var query =
@"INSERT INTO booking (operator_id, plot_id, postcode, datetime, stops, " +
"mileage, price, passengers, name, note, phone, status, reference) " +
"VALUES (@operator_id, @plot_id, @postcode, @datetime, @stops, " +
"@mileage, @price, @passengers, @name, @note, @phone, @status, @reference);";
var cmd = new MySqlCommand(query, DbConnect.Connection);
cmd.Parameters.AddWithValue(("@operator_id"), _operatorId);
cmd.Parameters.AddWithValue(("@plot_id"), _plotId);
cmd.Parameters.AddWithValue(("@postcode"), _postcode);
cmd.Parameters.AddWithValue(("@datetime"), _datetime);
cmd.Parameters.AddWithValue(("@stops"), _stops);
cmd.Parameters.AddWithValue(("@mileage"), _mileage);
cmd.Parameters.AddWithValue(("@price"), _price);
cmd.Parameters.AddWithValue(("@passengers"), _passengers);
cmd.Parameters.AddWithValue(("@name"), _name);
cmd.Parameters.AddWithValue(("@note"), _note);
cmd.Parameters.AddWithValue(("@phone"), _phone);
cmd.Parameters.AddWithValue(("@status"), Status);
cmd.Parameters.AddWithValue(("@reference"), _reference);
cmd.ExecuteNonQuery();

for (var i = 0; i < _waypointList.Count; i++)
{
query +=
@"INSERT INTO waypoint
(booking_id, sequence, address, lat, lng, reference)
VALUES
((select id FROM booking WHERE reference=@reference" + i + @"),
@sequence" + i + @",
@address" + i + @",
@lat" + i + @",
@lng" + i + @",
@reference" + i + ")";
cmd = new MySqlCommand(query, DbConnect.Connection);
cmd.Parameters.AddWithValue(("@reference" + i), _reference);
cmd.Parameters.AddWithValue(("@sequence" + i), i);
cmd.Parameters.AddWithValue(("@address" + i), _waypointList[i]);
cmd.Parameters.AddWithValue(("@lat" + i), _lat);
cmd.Parameters.AddWithValue(("@lng" + i), _lng);
cmd.ExecuteNonQuery();
}

最佳答案

这解决了它。

for (var i = 0; i < _waypointList.Count; i++)
{
query =
@"INSERT INTO waypoint
(booking_id, sequence, address, lat, lng, reference)
VALUES
((select id FROM booking WHERE reference=@reference" + i + @"),
@sequence" + i + @",
@address" + i + @",
@lat" + i + @",
@lng" + i + @",
@reference" + i + ")";
cmd = new MySqlCommand(query, DbConnect.Connection);
cmd.Parameters.AddWithValue(("@reference" + i), _reference);
cmd.Parameters.AddWithValue(("@sequence" + i), i);
cmd.Parameters.AddWithValue(("@address" + i), _waypointList[i]);
cmd.Parameters.AddWithValue(("@lat" + i), _lat);
cmd.Parameters.AddWithValue(("@lng" + i), _lng);
cmd.ExecuteNonQuery();
}

关于c# - 运行 2 个单独的查询但获取参数不应为空错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28260121/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com