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...
I have a SQL data reader that reads 2 columns from a sql db table.
once it has done its bit it then starts again selecting another 2 columns.
I would pull the whole lot in one go but that presents a whole other set of challenges.
My problem is that the table contains a large amount of data (some 3 million rows or so) which makes workin...
Hi all,
I've got a field in my SQL SPROC resultset that is a calculated CASE statement that returns 1 or 0 (ie True/False).
When I try to use the GetBoolean method of the SqlDataReader class and exception gets thrown.
Any suggestions would be appreciated.
...
When I write something like this:
using (var connection = new SqlConnection("ConnectionString"))
{
using(var cmd= new SqlCommand("Command"))
{
using (var reader = cmd.ExecuteReader())
{
while (reader.Read())
{
}
}
}
}
ReSharper shows warning on reader.Read(), and ...
I have an SQL query I get from a configuration file, this query usually contains 3-6 joins.
I need to find at run time, based on the result set represented by SqlDataReader, to find the name of the table for each column.
Here are some thing that don't work:
SqlDataReader.GetName returns the column name but not the table name.
SqlData...
Note: You may not need to read the whole thing to know what's wrong... skip down to the part about the 3 scenarios if you'd like. Only read the begin if you'd like some background info on how I've tried implementing this and where the errors occurred.
To begin with, I'm trying to retrieve a list of Clients stored in the CRM_Clients tabl...
I have a simple method that returns a Nullable Int32 from a DataReader rather than the built in GetInt32.
I am calling this method many many times and have one situation where any time I can shave off of it would be beneficial.
Can anyone suggest any alternative and faster ways of getting a nullable Int32 out of the DataReader?
privat...
I have a table of Users (tblUsers) which contains details of University staff. I am trying to populate a text box with the names of lecturers associated with a selected module.
I am getting all UserIDs associated with a particular module, testing if the User is a lecturer, if so then I add the ID to an ArrayList.
I then iterate throu...
Hello,
I have this relation:
Customer - Order - Product each mapped to its own sql table.
When I want to eager load now the Customers with its Orders and the Orders with its Products
How do I have to iterate the 3 sqldatareader to get in the end a IEnumerable just as
I would use an ORM.
What I do not want to do is to pass the Sql...
I have four different Business objects and each calls its corresponding FillBusinessObject method to fill all the individual object properties one by one. Now I wish to create a common method which should be able to fill each type of business object. I've created a base class from which all business objects inherit but I am not able to f...
Hello Friends,
I have two tables
Users (Userid, Name, PhoneNumber)
Applications (ApplicationsId,UserId, ApplicationName, ActiveDate)
Every user will have more than 1 application.
In Nhibernate using lazy loading I can get the users data along with all the applications for every user. So, I used to do something like user.applications...
So apparently, ExecuteReader is used for read only and ExecuteNonQuery is used for transactions. But for some reason even when I used ExecuteReader I am still able to run write (Insert, Update, Delete) commands (typed in textbox1). Is there something wrong with my code or am I misunderstanding the way ExecuteReader is supposed to work?
...
Hi,
I want to initialize a class with data coming from a MySql db. Some fields can be null:
Dim dr As MySqlDataReader = ...
Dim item As New Item(dr.GetInt16(0), dr.GetString(1), dr.GetString(2))
Suppose the last two fields could be NULL In the db, so that calling GetString on that field causes an exception.
I could certainly write ...
Hi!
This is incredibly urgent, I need to present this application in 3 and a half hours.
My application checks against a data source to see if a value exists in the database and changes values depending on whether or not the value in question was found.
The problem is that I've run the sql query with the value in question in SSMS and n...
Hi guys,
I know I asked a related question earlier. I just had another thought.
using (SqlConnection conn = new SqlConnection('blah blah'))
{
using(SqlCommand cmd = new SqlCommand(sqlStatement, conn))
{
conn.open();
SqlDataReader dr = cmd.ExecuteReader() //do I need to put this in using as well?
{
...
I use visual studio 2005 , but recently I've heard that there is a new technology which called entity framework .. should I move on and use it instead of using the usual SqlDataReader !!
the most important thing to me is the performance , note that I get the data from the DB using DataReader and return it as a generic List ..
any su...
Hi,
Recently i implemented Linq to SQL in a static class in my ASP.Net project which is a utility class to get some information on site load. when i used the static linqtosql datacontext i got the above error only in the live environment but never got that issue on UAT, or QA sites. ( this means this issue only happens when there is a m...
This is the code i have written to display the details of employee selected from the drop down list into textboxes. I didn't get any error but the details are not getting displayed in the textboxes...
protected void dlstemps_SelectedIndexChanged(object sender, EventArgs e)
{
int empno=Convert.ToInt32(dlstemps.SelectedItem.Value);
...
Hi I need some advice as to whether what I am trying to acheive is even possible.
I have code which is basically
SqlDataReader sourceDataReader = dbFunctions.getDataReader(<..some parameters..>)
while (sourceDataReader.Read())
{
.....
Do some stuff
.....
// Write out record
dbFun...
I tend to use
If Not IsDBNull(dr("data")) Then
myData = dr("data")
End If
to catch nulls. Is there a better way? It seems I use this over and over again? Anyone write a function to check this something like
mydata = IfNotNull("data")
I don't know how to handle the different data types that could be returned.
Thanks for any th...