Note that there are some explanatory texts on larger screens.

plurals
  1. POSQL DataReader missing a row in loop
    text
    copied!<p>When running the following code it leaves out one row. When I do a files.Count it says there are 4 rows but there is no data stored for the 4th row. When I run the stored procedure from within SQL Manager it returns all 4 rows and all the data. Any help?</p> <pre><code> List&lt;File&gt; files = new List&lt;File&gt;(); SqlConnection active_connection = new SqlConnection(m_connection_string); SqlCommand cmd = new SqlCommand(); SqlDataReader dr = null; try { active_connection.Open(); cmd.Connection = active_connection; cmd.CommandType = CommandType.StoredProcedure; cmd.CommandText = "dalsp_Select_Organization_Files"; SqlParameter param; param = cmd.Parameters.Add("@p_organization_guid", SqlDbType.UniqueIdentifier); param.Value = new Guid(organization_guid); param = cmd.Parameters.Add("@p_file_type", SqlDbType.NVarChar, 50); param.Value = file_type; dr = cmd.ExecuteReader(CommandBehavior.CloseConnection); if (dr.HasRows) { while (dr.Read()) { File file = new File(); file.OrganizationGuid = dr["OrganizationGuid"].ToString(); file.FileGuid = dr["FileGuid"].ToString(); file.FileLocation = dr["FileLocation"].ToString(); file.FileName = dr["FileName"].ToString(); file.FileType = (FileTypeEnum)Enum.Parse(typeof(FileTypeEnum), dr["FileType"].ToString()); file.FileExtension = dr["FileExtension"].ToString(); file.FileDescription = dr["FileDescription"].ToString(); file.ThumbnailPath = dr["ThumbnailPath"].ToString(); files.Add(file); } } dr.Close(); dr = null; active_connection.Close(); cmd = null; } catch (Exception) { throw; } finally { if (active_connection.State != ConnectionState.Closed) { active_connection.Close(); active_connection.Dispose(); } } return files; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload