sqldatareader

SqlDataReader Column Ordinals

Suppose I am calling a query "SELECT name, city, country FROM People". Once I execute my SqlDataReader do columns come in the same order as in my sql query? In other words can I rely that the following code will always work correctly: SqlConnection connection = new SqlConnection(MyConnectionString); SqlCommand command = new SqlCommand(...

SqlDataReader - result set cached?

When you use a SqlDataReader, is the return set completely determined by the ExecuteReader step, or can you influence what you get by writing to the source table(s) while reading? Here is an example in very rough pseudo code. sc = new SqlCommand("select * from people order by last, first",db) ; sdr = sc.ExecuteReader() ; while (sdr.rea...

.NET DataReader and SQL joins

string query = "SELECT * FROM table1, table2 WHERE table1.Id = table2.fId"; ... using(IDataReader dataReader = db.ExecuteReader(CommandType.Text, query)) .. string value = dataReader["table2.field"]; //dies I'm currently writing some .NET code which involves executing a join query and then accessing the returned data using a ...

looking for suggesions re: accessing data and populating List/arraylist/list

Hello All - I am looking to do something like this: access records in db with a datareader. I won't know how many records will come back - somewhere between 1 and 300 most of the time. The data will look something like this "0023","Eric","Harvest Circle", "Boston" for each record. I wanted to immediately populate something (array, list...

How can I make a function that can take a SQLDataReader and a DBDataRecord as a parameter?

I have a function that is normally called while looping inside a SqlDataReader, that will take data from that SqlDataReader and do some stuff with it. Now, I need to be able to also call it from inside a Data Bound Repeater object, that is also bound to a SqlDataReader... In the DataBound control, in the "OnDataBinding" event, I normal...

Is there a problem when I call SqlAdapter.Update and at the same time call SqlDataReader.Read

I have two applications, one updates a single table which has constant number of rows (128 rows) using SqlDataAdapter.Update method , and another application that select from this table periodically using SqlDataReader. sometimes the DataReader returns only 127 rows not 128, and the update application does not remove or even insert any ...

Why use the GetOrdinal() Method of the SqlDataReader

What's the difference between reading a value from an SqlDataReader using this syntax: Dim reader As SqlClient.SqlDataReader reader("value").ToString() OR Dim reader As SqlClient.SqlDataReader reader.GetString(reader.GetOrdinal("value")) ...

Parsing a decimal from a DataReader.

Hey all, I found a workaround for this error, but am now really curious as to why this would be happening, was wondering if anyone else has had this error. My function is as follows: public void Blog_GetRating(int blogID, ref decimal rating, ref int voteCount) { // Sql statements // Sql commands if(DataReader.Read()) ...

Reading SP with output parameters and result set in C#?

I have created a stored procedure similar to this simplified example: CREATE PROCEDURE dbo.sp_MyStoredProcedure @Var1 INT OUTPUT, @Var2 DECIMAL(10,2) OUTPUT AS BEGIN SET NOCOUNT ON; SELECT @Var1 = COUNT(*), @Var2 = SUM(TranAmount) FROM MyTable SELECT * FROM MyTable END When I try to re...

how to get number of rows using SqlDataReader in C#

Hi, my question is about how to get number of rows using SqlDataReader in C#. I've seen some answers around the net about this but none were clearly defined except for one that states to do a while loop with Read() method and increment a counter. My problem is that I am trying to fill a multi-dimensional array with the first row being t...

Keeping the SqlDataReader open across an n-tiered layer

I have a Database class that abstracts the ExecuteNonQuery() and ExecuteReader() of SqlCommand. Due to wrapping the Sqlconnection and SqlCommand around using blocks, the SqlDataReader gets closed after the CustomExecuteReader() is called, therefore I can't read the SqlReaderResultSet at the business level layer. Code below. Thanks guys f...

ADO.Net DataReader timeout issue

Hello everyone, I am using ADO.Net + C# + VSTS 2008 + ADO.Net to connect to SQL Server 2008 Enterprise. I am using almost the same pattern/sample mentioned here -- using ADO.Net DataReader to retrieve data one entry (row) by one entry (row). http://msdn.microsoft.com/en-us/library/haa3afyz.aspx My question is, if I set the SqlCommand ...

SqlDataReader.Read() always returning false

Hi, I have the following situation: using (SqlConnection conexao = new SqlConnection(ConnectionString)) { SqlCommand comando = new SqlCommand(query, conexao); comando.Parameters.AddWithValue("id", idUsuario); conexao.Open(); SqlDataReader reader = comando.ExecuteReader(CommandBehavior.SingleRow); if (reader.Read()) ...

No results returned to a reader but the same query works thru SQL Management Studio

Hello, I'm experiencing weird behavior with some of full text search queries, especially those with multiple words. These are working fine when executed thru Management Studio but returning no results when called from a code. I did a SQL Trace to see what commands are being sent from my app and exactly same command come with results wh...

Advantages of using SQLDataReader over a reader that implements IDatareader?

What are the advantages of using a SQLDataReader as opposed to a reader that just implements IDatareader if I'm using SQL Server >= 2005? Does the SQLDatareader simply have more functionality to choose from, or are there performance improvements using the SQLDatareader? Any articles that discuss this would be appreciated. Thanks! Ch...

DataReader associated with this Command which must be closed first.

I am getting the following error; "There is already an open DataReader associated with this Command which must be closed first." is it because I have used the reader in foreach loop ? or what the problem might be ? Regards BK foreach( Apple a in listApple ) { .... using (SmartSqlReader reader = Db.CurrentDb.Execu...

VB.net / C# dont reference sqlreader in client portion then where?

Assume I have a form that has say 5 text boxes and I need to pull some data from a database then set those 5 text boxes with that data. So assume I have 3 basic layers: the code behind for a default.aspx page a BLL class that contacts the DAL and a data access layer (DAL) But I've heard and read that the default.aspx page should no...

Performance Concerns between DataTable and SqlDataReader to fill Data with FlexGrid

Which one is more faster between DataTable and SqlDataReader while I'm trying to fill Data into FlexGrid with VB.NET? ...

SqlDataReader, a firehose cursor - no buffering?

So I understand SqlDataReader is quite fast, you dont know how many rows you'll get and it only allocates memory for each row at a time. So if I have a million rows of small rows (say 4 to 32 bytes) each row read means a roundtrip to the server? No buffering takes place right? If I used ODBC via SQL Native Client I could setup a row buf...

How to use PagedDataSource.CopyTo (or otherwise work with the same data I'm sending to my Repeater)

I'm populating a Repeater with a PagedDataSource and after I populate that Repeater, I want to perform some other operations on the subset of data that makes up the page I'm sending to the Repeater (my CurrentPageIndex, PageSize=10). So my question is how to get at those 10 records? From reviewing MSDN, it looks like I should be able t...