datareader

ASP.net DataReader execution technique

I am a beginner. I heard that DataReader works on forward only readonly fashion and at a time it will read a single record.Suppose when i execute the below code SqlDataReader reader=cmd.ExecuteReader(); gv1.DataSource=reader; gv.DataBind(); How the does the gridview populate all records?.As the reader is capable of reading one row...

Datareader skips first result

I have a fairly complex SQL query that pulls different types of products from a database based on a customer ID. It pulls three different types of products, identified by their unique identifier number ranges (i.e., IDs 1000-1999 are one type of product, 2000-2999 are another, and 3000-3999 are yet another). SELECT b.fldMachineName, m2....

When DataReader become empty?

I have the below code : if (reader.HasRows) { while (reader.Read()) { DataRow searchedDR = ds.Tables[dr["name"].ToString()].Rows.Find(reader["ID"].ToString()); if (searchedDR != null) ds.Tables[dr["name"].ToString()].Rows.Remove(searchedDR); } } When this block of code done successfully the data...

Oracle DataReader returns 1 row but Read method returns false

I have a basic sql statement that looks up a user and returns one record but when I run a block of code that says if(myReader.Read()) it returns false. I have stepped through the code and examined the reader object and it does in fact contain one record. below is the code. sql: SELECT user_name, user_password, user_state FROM users W...

NpgSQLdataReader GetOrdinal throwing exceptions.. any way around?

I built a wrapper around NpgSQL for a bunch of the methods I usually use in my projects' DAL. Two of them, I usually use to fill DTOs straight from a DataReader. Usually in a fill helper method, i'll instanciate the DTO and iterate through the properties mapping the Datareader's data to the corresponding property. The fill method is gene...

DataReader-DataSet Hybrid solution

My solution architects and I have exhausted both pure Dataset and Datareader solutions. Basically we have a Microsoft.NET 2.0 windows service application that pulls data based on a query and processes additional tasks per record; almost a poor mans workflow system. The recordsets are broader (in terms of the columns) and deeper (in terms...

Handle DBNull in C#

Is there a better/cleaner way to do this? int stockvalue = 0; if (!Convert.IsDBNull(reader["StockValue"])) stockvalue = (int)reader["StockValue"]; ...

Read from multiple tables in vb.net data reader

I'm trying to read from two tables in mysql: Dim sqlcom As MySqlCommand = New MySqlCommand("Select * from mother, father where IDNO= '" & TextBox14.Text & "' ", sqlcon) -But I get this error: Column 'IDNO' in where clause is ambiguous Here is the whole code: Dim NoAcc As String Dim NoAccmod2 As String Dim NoPas A...

How to read a database record with a DataReader and add it to a DataTable

Hello I have some data in a Oracle database table(around 4 million records) which i want to transform and store in a MSSQL database using ADO.NET. So far i used (for much smaller tables) a DataAdapter to read the data out of the Oracle DataBase and add the DataTable to a DataSet for further processing. When i tried this with my huge t...

Strange problem with DataReader?

I am facing a strange issue with DataReader. I am using OdbcClient with a legacy rdbms system. I am sending follwing command to the database. select Col1, Col2, Col3 from Table1 where Col2 = 'Val1'; However in certain cases when I iterate it through DataReader as shown below. IDataReader reader = cmd.ExecuteReader(); while(reader.R...

Close reader before closing connection

Should you always close a DataReader before closing the connection, or is it okay to just close the connection? By just closing the connection does that effectively close the reader? (This is for c#.net 3.5) Thanks! ...

C# object creation from datatable

I'm just getting my head round C#. I've been creating classes and objects so say i created a class called Member: public class Member { public int MemberID; public string FirstName; public string LastName; public string UserName; } and I create a new object of that class by doing this: Member Billy = new Me...

Dropdownlist and Datareader

After trying many solutions listed on the internet I am very confused now. I have a C#/SQL web application for which I am simply trying to bind an ExecuteReader command to a Dropdownlist so the user can select a value. This is a VS2008 project on an XP OS. How it works is after the user selects a table, I use this selection as an inp...

Setting DataReader = nothing

Hi all, In my project I have seen that at many places developer has just nullify the DataReader object after use and hasn't close or dispose.. I want to know the advace effect of doing so, I mean nullifying the datareader and not closeing them. Thanks and Regards, Tanmay. ...

DataReader, DataAdapter & DataSet - When to use?

I want to know when i have to use these ADO.NET Components???can anyone brief it with an example??? ...

update each recordset with datareader

hi, my situation is the following: i have a datareader and loop over all records returned by a select statement and then call a function with a value from that row. but now i need to update a column in each row, after the function has been called. using a separate update statement seems like a huge overkill. what's the best method to d...

How to print all columns in a datareader

Using c# how do I print all columns in a datareader. ...

SQL DataReader how to show null-values from query

I have a DataReader and a StringBuilder (C#.NET) used in the following way; while (reader.Read()) { sb.AppendFormat("{0},{1},{2},",reader["Col1"], reader["Col2"], reader["Col3"]); } Which works great for my use, but when a row is null I need it to return "null", inste...

DataReader - hardcode ordinals?

When returning data from a DataReader I would typically use the ordinal reference on the DataReader to grab the relevant column: if (dr.HasRows) Console.WriteLine(dr[0].ToString()); (OR dr.GetString(0); OR (string)dr[0];)... I have always done this because I was advised at an early stage that using dr["ColumnName"] or a m...

How to initialize F# list when size is unknown, using while..do loop

I have a function that will parse the results of a DataReader, and I don't know how many items are returned, so I want to use a while..do loop to iterate over the reader, and the outcome should be a list of a certain type. (fun(reader) -> [ while reader.Read() do new CityType(Id=(reader.Ge...