所以我有这个类,有C#功能与预留和释放席位一起工作。无论如何,在调试模式下,while被检查,然后突然其内容被跳过。我认为没有结果集返回读取实际访问?但我能做什么?因为这段代码在工作,突然就停止...c#不能访问阅读器sql
string queryRangeForCheck = "select * from DateTest WHERE datefill between @startdate AND @enddate";
SqlConnection conn = new SqlConnection("....");
conn.Open();
SqlCommand command = new SqlCommand(queryRangeForCheck, conn);
command.Parameters.AddWithValue("@startdate", startDate);
command.Parameters.AddWithValue("@enddate", endDate);
SqlDataReader reader = command.ExecuteReader();
int bookingStatus = 2;
//for the range found do:
while (reader.Read())
{
//establish the number of seats available for this date
int currentRow = Convert.ToInt32(reader["seats"]);
//if the number is > 0 i.e. if not fully booked
if (currentRow != 0)
{
//if the number of seats can accomodate the number required
if (currentRow >= requiredSeats)
{
....
请指点 感谢
唯一奇怪/坏你的代码是,你不括在'using'声明你的数据库连接,以及是否出售,或不晚于目前还不清楚。 – Icarus
如果它跳过了,那么没有与DB中的条件相匹配的数据...因此,您要么检查数据库中的数据,要么处理代码中的这种情况... – Yahia
我会处理它,但我不知道使用事情......因为在C#中很新颖(就像一个月新)。将确保我添加它。因为日期是作为函数参数发送的,所以我发现它们的格式不是预期的,因此是错误。仍在努力。 –