sqldatareader

SqlDataReader does not return all records (3rd attempt)

怎甘沉沦 提交于 2019-12-02 01:58:45
I've tried to find solution for this problem twice before, but unfortunately those answers haven't provided permanent fix, so here I am, giving it another try. I have an SQL Server stored procedure that returns list of 1.5 million integer IDs. I am calling this SP from ASP.NET/VB.NET code and executing a SqlDataReader: m_dbSel.CommandType = CommandType.StoredProcedure m_dbSel.CommandText = CstSearch.SQL.SP_RS_SEARCH_EX oResult = m_dbSel.ExecuteReader(CommandBehavior.CloseConnection) Then I am passing that reader to a class constructor to build Generic List(Of Integer). The code is very basic:

Gridview not populating while using a While() structure. C# ASP.Net

牧云@^-^@ 提交于 2019-12-02 01:00:44
I am having problems with this grid view. I am populating it with a query. However, it will not populate or even appear if I use a while(reader.Read()) structure. Without the while structure, it works fine. However, I need to access two specific fields. The code is below. SqlDataReader myReader; try { using (myConnection) { myConnection.Open(); ArrayList arrliGames = new ArrayList(); myReader = myCommand.ExecuteReader(); decimal decTicketCost = 0; int intTicketCount = 0; while (myReader.Read ()) { decTicketCost = Convert .ToDecimal (myReader ["TicketCost"]); intTicketCount =Convert .ToInt32

Out of range error on SqlDataReader

为君一笑 提交于 2019-12-02 00:47:08
问题 I'm using a SqlDataReader and get this exception when trying to read a column... System.IndexOutOfRangeException: record Here is the code... SqlCommand select = new SqlCommand("SELECT RTRIM(LTRIM(PART_NO)) AS PART_NO, record AS CUSTOMER_NO FROM [RMAData].[dbo].[IMPORTING_ORDER_EDI] WHERE sessionID = '" + Session.SessionID + "'", connection); SqlDataReader reader = select.ExecuteReader(); if (reader.HasRows) { while (reader.Read()) { lblWebMasterMessage.Text += "record " + reader["record"]

DataReader cursor rewind

筅森魡賤 提交于 2019-12-01 22:01:33
How do I can rewind a cursor of a DataReader to the beginning? With one DataReader result I need to run two while loop, but those have to be from beginning. They are two iterations in one result set running a query once. Example: dr = command.ExecuteReader(cmd); while (dr.Read()) { // do some... } // rewind cursor here while (dr.Read()) { // do another things... } I've looked into the DataReader docs and I've found nothing, so if it can't be possible with DataReader, I may change the class for one that fits this purpose. You cannot (unless you execute the command again): it is a one-way stream

Out of range error on SqlDataReader

╄→尐↘猪︶ㄣ 提交于 2019-12-01 21:46:17
I'm using a SqlDataReader and get this exception when trying to read a column... System.IndexOutOfRangeException: record Here is the code... SqlCommand select = new SqlCommand("SELECT RTRIM(LTRIM(PART_NO)) AS PART_NO, record AS CUSTOMER_NO FROM [RMAData].[dbo].[IMPORTING_ORDER_EDI] WHERE sessionID = '" + Session.SessionID + "'", connection); SqlDataReader reader = select.ExecuteReader(); if (reader.HasRows) { while (reader.Read()) { lblWebMasterMessage.Text += "record " + reader["record"].ToString() + "<br />"; ... If I change the lblWebMasterMessage.Text to the following it works just fine...

Is closing/disposing an SqlDataReader needed if you are already closing the SqlConnection?

筅森魡賤 提交于 2019-12-01 21:03:56
I noticed This question , but my question is a bit more specific. Is there any advantage to using using (SqlConnection conn = new SqlConnection(conStr)) { using (SqlCommand command = new SqlCommand()) { // dostuff } } instead of using (SqlConnection conn = new SqlConnection(conStr)) { SqlCommand command = new SqlCommand(); // dostuff } Obviously it does matter if you plan to run more than one command with the same connection, since closing an SqlDataReader is more efficient than closing and reopening a connection (calling conn.Close();conn.Open(); will also free up the connection). I see many

DataReader has rows and data, trying to read from it says “no data is present”

对着背影说爱祢 提交于 2019-12-01 20:45:46
问题 I haven't used DataReaders in ages (I prefer to use an ORM) but I'm forced to at work. I pull back the rows, and check that HasRows is true; debugging at this point and examining the reader shows that my data is there. Now here's the issue: the moment I call reader.Read() , trying to expand the results says "The enumeration yielded no results" or whatever, and I get the "Invalid attempt to read when no data is present." error. I get the same thing if I don't call Read() (which is the default

DataReader has rows and data, trying to read from it says “no data is present”

北城余情 提交于 2019-12-01 20:04:31
I haven't used DataReaders in ages (I prefer to use an ORM) but I'm forced to at work. I pull back the rows, and check that HasRows is true; debugging at this point and examining the reader shows that my data is there. Now here's the issue: the moment I call reader.Read() , trying to expand the results says "The enumeration yielded no results" or whatever, and I get the "Invalid attempt to read when no data is present." error. I get the same thing if I don't call Read() (which is the default since the DataReader starts before the first record). I cannot remember the proper way to handle this;

SqlDataReader are these two the same Which one is faster

旧时模样 提交于 2019-12-01 19:54:14
I am working with SqlXml and the stored procedure that returns a xml rather than raw data. How does one actually read the data when returned is a xml and does not know about the column names. I used the below versions and have heard getting data from SqlDataReader through ordinal is faster than through column name. Please advice on which is best and with a valid reason or proof sqlDataReaderInstance.GetString(0); sqlDataReaderInstance[0]; and have heard getting data from SqlDataReader through ordinal is faster than through column name Both your examples are getting data through the index

SqlDataReader “Enumeration yielded no results”

霸气de小男生 提交于 2019-12-01 19:41:11
Been trying to figure out, but I can't. I execute a Stored Procedure via SqlCommand and the SqlDatareader object that is returned doesn't give me the results, however, I can see them if a explore the object in the debugger. here's an image of what I'm talking about: In the Result View row it says " Enumeration yielded no results " but in the path: base -> base -> ResultView -> [0] -> Non-Public members -> _values -> [0], 1 ,[2],[3] the results are shown. Anyone has an idea how to get them? This is the code I'm using to get and specific column: if (dataReader.Read()) { ProjectFolderId =