Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/29.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# c不访问读卡器sql_C#_Asp.net_Sql - Fatal编程技术网

C# c不访问读卡器sql

C# c不访问读卡器sql,c#,asp.net,sql,C#,Asp.net,Sql,所以我有一个类,它有c函数来处理预订和释放座位。无论如何,在调试模式下,检查while,然后突然跳过其内容。我假设没有返回任何结果集供读取以实际访问?但是我能做什么呢?因为这个代码正在工作,突然它停止了 string queryRangeForCheck = "select * from DateTest WHERE datefill between @startdate AND @enddate"; SqlConnection conn = new SqlConnection

所以我有一个类,它有c函数来处理预订和释放座位。无论如何,在调试模式下,检查while,然后突然跳过其内容。我假设没有返回任何结果集供读取以实际访问?但是我能做什么呢?因为这个代码正在工作,突然它停止了

 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)
                {
                  ....
请指教
谢谢

尝试使用HasRows属性检查读卡器是否有行

此外,创建一个新表并用读取器加载该表。这将关闭读卡器,但您将能够使用数据集调试可视化工具来检查结果。然后再次执行该命令。在下面的代码段中,该命令返回多个结果集。因此,我一直在加载表,直到在调用Load方法期间关闭读取器

            oReader = Me.SelectCommand.ExecuteReader(CommandBehavior.CloseConnection Or CommandBehavior.KeyInfo)

#If DbDebug Then

        'load method internally advances to the next result set
        'therefore, must check to see if reader is closed instead of calling next result

        Do
            Dim oTable As New DataTable("Table")
            oTable.Load(oReader)
            'Inspect oTable here as needed.
            oTable.WriteXml("C:\" + Environment.TickCount.ToString + ".xml")
            oTable.Dispose()
        Loop While oReader.IsClosed = False

        'must re-open the connection
        Me.SelectCommand.Connection.Open()

        'reload data reader
        oReader = Me.SelectCommand.ExecuteReader(CommandBehavior.CloseConnection Or CommandBehavior.KeyInfo)

#End If

主要问题是读者没有返回任何内容。这是由于传递和预期的日期参数的类型和格式造成的。因此它不匹配,无法返回任何结果。当日期以mm/dd/yyyy格式重新格式化时,实际上一切都正常。感谢大家的宝贵意见:

您的代码中唯一奇怪/糟糕的地方是,您没有将db连接包含在using语句中,并且不清楚您以后是否要处理它。如果跳过它,则没有与db中的条件匹配的数据。。。所以你要么检查数据库中的数据,要么在代码中处理这种情况……我确实处理了它,但我不知道如何使用它……因为我在C语言中非常新,就像一个月前一样。我会确保添加它。因为日期是作为函数参数发送的,所以我发现它们的格式与预期不同,因此出现了错误。仍在处理中。是@Yahia这是真的…我正在确认iTuhmm我认为并非所有while循环的可能路由都会在数据读取器进入下一个路由之前关闭数据读取器如果您传入日期对象而不是日期字符串,则不应导致格式问题。