I seem to always have problems with converting data to and from XML in C#. It always wants you to create a full XMLDocument object even when you think you shouldn't have to. In this case I have a SQLXML column in a MS SQL 2005 server that I am trying to pull out and push into a function that requires an XMLNode as a parameter. You would ...
I've got an ASP.NET page that has a bunch of controls that need to be populated (e.g. dropdown lists).
I'd like to make a single trip to the db and bring back multiple recordsets instead of making a round-trip for each control.
I could bring back multiple tables in a DataSet, or I could bring back a DataReader and use '.NextResult' to ...
Is there any way I can push a new record to SqlDataReader after i pull a table down? I have this piece of trash code that I need to modify, and this seems like the easiest way to do what I need. I understand that this should not be done, and if you have to do it there is something seriously wrong with your logic, but is there a way?
...
I am cleaning up the DataReaders in an old .NET 1.1 project that I inherited.
The previous developer coded the data-access-layer in such a way that most of the DAL methods returned SqlDataReaders (thus leaving it up to the caller to properly call the .Close() or .Dispose() methods).
I have come across a situation, though, where a cal...
How do I check to see if a column exists in a SqlDataReader object? In my data access layer, I have create a method that builds the same object for multiple stored procedures calls. One of the stored procedures has an additional column that is not used by the other stored procedures. I want to modified the method to accommodate for ev...
What are the advantages of replacing (int)reader[0] with reader.GetInt32(0)? I'm sure such casting functions are there for a reason, but other than it feeling more aesthetically pleasing to avoid the cast myself, I'm not sure what those reasons are.
...
I'm currently writing a C#-class in my ASP.NET (3.5) application to handle all database-queries. Some of the methods are there to make a select-query to the database. Inside the method i simply have a SqlDataReader r = command.ExecuteReader(); to fetch the data.
I now want r to be returned by the method, but when i close the database-co...
I am working on a DAL that is getting a DataReader Asynchronously.
I would like to write a single method for transforming the DataReader into a DataSet. It needs to handle different schema so that this one method will handle all of my fetch needs.
P.S. I am populating the SQLDataReader Asynchronously, please don't give answers that ...
When accessing values from an SqlDataReader is there a performance difference between these two:
string key = reader.GetString("Key");
or
string key = reader["Key"].ToString();
In this code sample:
string key;
using (SqlDataReader reader = cmd.ExecuteReader())
{
while (reader.Read())
{
key = reader.GetString("Key"...
Hello,
I've come to StackOverflow before with this quest:
http://stackoverflow.com/questions/547040/ms-sql2005-query-stored-proc-results-to-text-using-sqlcommand-or-such
I was told to build the string myself so that I get the same results as from SQL Managment Studio's Results To Text (Cntrl + T)
I have now run into a problem, how ...
I've query executing ~2 secs in MSSMS (returning 25K of rows)
Same query used in .NET (sqlReader) exetuting few minutes!
I've also tried to execute only reader
(commented all code in while loop just leaving reader.Read() ) - still same!
Any idea what's up?
...
Hi
Is it better to create lots of SQL statements or to cache the data in asp .NET and manipulate the data from there?
cheers
...
Hi,
After connecting to the database, can I get the name of the all the columns that where returned in my sqldatareader?
...
I have coded three select statements in stored procedure in Microsoft SQL Server 2005. Both select statements return multiple number of records and table list for select statements is different. One select records from a master table and the other from a child table. In C# code I want to get all these records and put all the data in one ...
I am updating a web application and have decided to use SubSonic as it seems awesome and I want to learn it :) I'm trying to return a SQLDataReader from a method I already have and have done it like this
public SqlDataReader GetAllCarTypes_dr()
{
return (SqlDataReader)new Query("tblCarType").ExecuteReader();
}
Just checking this ...
I have a datareader that return a lsit of records from a sql server database. I have a field in the database called "Additional". This field is 50% of the time empty or null.
I am trying to write code that checks if this field isnull. The logic behind this is:
If the field "Additional" contains text then display the info otherwise hide...
Ok, I asked about this very error earlier this week and had some very helpful answers and without doubt things have drastically improved since I started following the suggestions.
However, now I am using the 'correct', best practice method to access the database I still get this error on some functions and I cannot get it to disappear f...
I have a small C# function that takes any generic SQLDataReader and converts it to a csv file. However I now need to ignore 1 column from a datareader that gets passed into it.
How can I remove 1 column from the SQLDataReader?
This column is needed in the query mainly for ordering but is used in another area on the same pageload, but ...
I'm maintaining some C# 2.0 code and the programmer uses a pattern of reading a collection of business objects by opening a datareader and then passing it to the object's constructor. I can't see anything obviously wrong with this but it feels bad to me. Is this OK to do?
private static void GetObjects()
{
List<MyObject> objects = ...
Is there an easy way to convert all the columns of the current row of a SqlDataReader to a dictionary?
using (SqlDataReader opReader = command.ExecuteReader())
{
// Convert the current row to a dictionary
}
Thanks
...