Difference Between SqlDataReader.NextResult() And MARS

Sep 19, 2010

hile i have been working with application perfomance tuning part i found an article for doing the same from Microsoft. it suggests me to reduce the round trip between application and database by using Sqlbatch statements. i got two ways to achieve it 1. SqlDataReader.NextResult() - we can use single connection to execute sql batch statements2. MARS (Multiple Active Result Sets) - we can use single connection to open multiple readers and execute the batch statements

View 2 Replies


Similar Messages:

Forms Data Controls :: Check For Null In Second Query When Using SqlDataReader.NextResult?

Jan 28, 2010

When using SqlDataReader.NextResult for 2 queries I am trying to I check if the second query returns any rows, but whether it has any rows or not the repeater2 is never hidden/false . I am doing something like this:

[Code]....

View 2 Replies

Databases :: Recursive TreeView Without MARS?

Feb 20, 2011

I'm trying to implement a TreeView exactly like this:http://www.matthidinger.com/archive/2009/02/08/asp.net-mvc-recursive-treeview-helper.aspxThe problem is, that I'm using MySQL which doesn't support MARS (Multiple Active Result Sets).So, how would I do this, without being able to use MARS?

View 4 Replies

DataSource Controls :: MARS - "There Is Already An Open DataReader Associated With This Command Which Must Be Closed "

Feb 23, 2010

I am using MS SQL Server 2005 and i added "" to my connection string and i still have the problem

"There is already an open DataReader associated with this Command which must be closed" ;

SqlDataReader dr2;
StrSql = " SELECT * from Modules";
cmd.Connection = conn;
cmd.CommandText = StrSql; [code]....

View 1 Replies

SQLDataReader Find Value Of Each Row?

Nov 10, 2010

I used to use datasets instead of sqldatareaders and I used to be able to do something like this

If dataset.tables(0).Rows(0)(1).ToString()) = "N" Then
lbl.Text = dataset.tables(0).Rows(0)(2).ToString())
Else
'Do Nothing
End If

This obviously doesn't work with sqldatareaders.I have code to see if the SQLDatareader has any rows but was wondering if there was a way to get the value of each rowI'm guessing this is possible and i've had a look around but can't seem to find anything

Dim conn As SqlConnection = New SqlConnection("server='h'; user id='w'; password='w'; database='w'; pooling='false'")
conn.Open()
Dim query As New SqlCommand("DECLARE @investor varchar(10), @sql varchar(1000) Select @investor = 69836 select @sql = 'SELECT * FROM OPENQUERY(db,''SELECT * FROM table WHERE investor = ''''' + @investor + ''''''')' EXEC(@sql)", conn)
Dim oDR As SqlDataReader = query.ExecuteReader()
If oDR.HasRows or dataset.tables(0).Rows(0)(1).ToString()) = "N" Then
lbl.Text = dataset.tables(0).Rows(0)(2).ToString())
Else
'Do Nothing
End If

That is the code I have at the moment which obviously doesn't work

View 2 Replies

Using SqlDataReader In Linq?

Sep 7, 2010

In normal way of write the code as follows in DAL.

DataSet ds=db.executedataset();
IEnumerable<datarow>= ds.tables[0].asEnumerable();

For better performance can use datareader in Linq instead of DataSet

View 11 Replies

SqlDataReader To String[]?

Mar 20, 2011

why the following code doesn't work?

internal static string[] GetToolsForRole(string selectedRole) {
string[] tempStr;
ArrayList myAL = new ArrayList();

[code]...

View 2 Replies

ADO.NET :: How To Get The Number Of Rows From Sqldatareader

Mar 29, 2011

how to get the number of rows from sqldatareader

View 2 Replies

C# - Read Data From SqlDataReader?

Oct 25, 2010

I have a SQL Server 2008 database and I am working on it in the backend. I am working on asp.net/C#

SqlDataReader rdr = cmd.ExecuteReader();
while (rdr.Read())
{
//how do I read strings here????
}

I know that the reader has values. My SQL command is to select just 1 column from a table. The column contains strings ONLY. I want to read the strings (rows) in the reader one by one. How do I do this?

View 5 Replies

ADO.NET :: Load List From Sqldatareader?

Feb 26, 2011

How can you load a List<> object from a Datareader?I tried to do it but for some reason it is not working. Below is the code that I tried to use:

using System;
using System.Data;
using System.Configuration;

[code]...

View 1 Replies

Web Forms :: SqlDatareader Is Null?

Jul 20, 2010

This my code SHoul the sqldatareader even be null when i debug (becuase response write not working)

[Code]....

View 4 Replies

ADO.NET :: Get Two Rows Details In Variables Using SQLdatareader?

Mar 12, 2011

i need to Get Two rows details in variables using SQLdatareader and using while loop in it.Can i do so,

my query and while loop are getting fired when i debug and see my while loop...but i dnt know how to get details and show or store it, when i will get 2 records on execution of query.

MY CODE IS BELOW...

[Code]....

View 4 Replies

C# - Cannot Read Multiple Rows From Sqldatareader

Apr 15, 2010

When I query for only one record/row, sqldatareader is giving correct result but when i query for multiple rows, its giving error on the client side. below is my code.

[code]....

View 3 Replies

DataSource Controls :: SqlDataReader Does Not Get Results

Aug 19, 2010

I am trying to run a stored proc from this function. When I run it thorugh the debugger I can see that myReader.HasRows = true and myReader.FieldCount =14.

But the control does not go in the loop while (myReader.Read()) where I am trying to read Version field returned by the stored proc.

[Code]....

View 3 Replies

C# - Use UserControl To Display SqlDataReader Data?

May 13, 2010

i try to use userControl to display SqlDataReader data.

in the main page

public SqlDataReader Data2;
...
<uc1:WebUserControl ID="WebUserControl1" RData1="<%=Data2 %>" runat="server" />
and in the userControl
Repeater1.DataSource = RData1;
Repeater1.DataBind();........

But i keep getting this error

Cannot create an object of type 'System.Data.SqlClient.SqlDataReader' from its string representation '<%=Data2 %>' for the 'RData1' property.

View 1 Replies

.net - SqlDataReader Is Drops Columns Randomly?

Jan 16, 2011

I have a very strange issue, I'm using System.Data.SqlClient. to get data from a SQL Server though a stored procedure. When I test the Application at the Development and Stagging machines it works fine but when I deploy the application on the Production Server I randomly getting an SqlDataReader IndexOutOfRangeException with different column names!.The error appears in 2 requests in each 1000 request (approximative).

public static List<CountryInfo> GetAllCountries(){
List<CountryInfo> Items = new List<CountryInfo>();
try{
using (rdr = SqlHelper.ExecuteReader(Globals.ConnectionString, "unv_spGetAllCountries"))
[code]...

View 2 Replies

C# - Create JSON String From SqlDataReader?

Apr 4, 2011

I'm using Json.NET and I'm trying to create a JSON string representing a row from a database table to return in an HTTP response. I'm not sure how to do this while I'm reading from the database.The problem is marked by the obnoxious comments /******** ********/

// connect to DB
theSqlConnection.Open(); // open the connection
SqlDataReader reader = sqlCommand.ExecuteReader();

[code]...

View 1 Replies

DataSource Controls :: Get ArrayList Value In SqlDataReader

Sep 24, 2010

I'm trying to convert some code from VB to C# on a site i'm working on and can't seem to get the arraylist to function properly.

Here is what we currently have in the codebehind:

[Code]....

Which we then call from the page using:

[Code]....

I want to convert this to C# as the rest of the code on the new site is in C# and I'm having problems with the ArrayList. I've got the other parts of the code all converted fine it's just the GetContent Function that isn't working right. Here's what I have:

[Code]....

I got an error on the "objSDR.Item" part of the code saying "SqlDataReader doesn't have definition for Item" and so if I changed this to the code above. Only problem now is I can't call this from the page using the code below as there is no "Item" in the GetContent Function any more

[Code]....

[Code]....

View 8 Replies

DataSource Controls :: Read A Bit Value From DB With SqlDataReader?

May 2, 2010

In SQL Server 2008 bit is like boolean (true/false), but I tried to read the bit value (0 or 1) and got error. How can I read it?

[Code]....

View 1 Replies

DataSource Controls :: How To Read Data From The SqlDataReader .

Apr 18, 2010

how to read data from the sqlDataReader .

sqlDataReader sdr = sql_comm.executeDataReader();
if(sdr.hasRows)
{
while(sdr.read)
i=0
[code]...

View 3 Replies

Using Statement When Setting Control's Datasource To Sqldatareader

Aug 25, 2010

I know it is recommended to use a using statement with a sqldatareader, but I was wondering if it is necessary when you are setting the datasource of a control to a datasource directly. in some places in my code I do this.

using (SqlDataReader reader = getReader())
{
while (reader.Read())
{
// do stuff with data
}
}

when binding to a control I do this.

ddlCustomer.DataSource = getReader(); // get Reader returns a sqldataReader
ddlCustomer.DataBind();

In the second case, do I need to use a using statement. Do i have to first declare an SqlDataReader in a using statement, then set the DataSource to that object. Seems like more clutter in the code, so i was hoping binding to the SqlDataReader disploses of the SqlDataReader.

View 3 Replies

DataSource Controls :: Why SqlDataReader Class Is Not Instantiated

Feb 18, 2010

Why SqlDataReader Class object is not created by "new" Operator.

Is it not possible to create the object like below

SqlDataReader dr=new SqlDataReader();

dr=cmd.ExecuteReader();

Why the constructor of the SqlDataReader class is internal?

View 2 Replies

ADO.NET :: Retrieving Bit Colum With Sqldatareader For Vb Class Property?

Oct 3, 2010

I have a vb class that reads a single row of data from an SQL view. I want to add a property to it that will expose the value of a new bit field. But whatever I do my class always returns the value "false".What am I doing wrong?

Public ReadOnly Property IsPublished() As Boolean
Get
Return valPublished
End Get
End Property

Here's the relevant line from my datareader: Me.valPublished = Convert.ToBoolean(theObjectReader("Authorised"))Authorised is my bit field. I have tried it with and without the "ConvertToBoolean" statement.When I response write the value of the property for rows where this field is true, it always shows false.

View 4 Replies

Cannot Retrieve Output Parameters Until SqlDataReader Is Closed

Apr 13, 2010

While the SqlDataReader is being used, the associated SqlConnection is busy serving the SqlDataReader, and no other operations can be performed on the SqlConnection other than closing it. This is the case until the Close method of the SqlDataReader is called. For example, you cannot retrieve output parameters until after you call Close.

If the above claim is true, then why is the following method able to retrieve a value from output parameter before the reader is closed:

public int Something()
{
using (SqlConnection con = new SqlConnection(this.ConnectionString))
{
SqlCommand cmd = new SqlCommand("some_procedure", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@ID", SqlDbType.Int).Direction = ParameterDirection.Output;
con.Open();
cmd.ExecuteReader();
return (int)cmd.Parameters["@ID"].Value;
}
}

You can reset the CommandText property and reuse the SqlCommand object. However, you must close the SqlDataReader before you can execute a new or previous command.

Why must you close sqldatareader before you execute new command?

View 2 Replies

SQL Server :: Return Sum Of 2 Subsets To Single SqlDataReader?

Sep 20, 2010

I still have plenty to learn about SQL... I'm pretty sure what I want to do is possible, but I'm getting lost in the syntax.

I have two tables:

TABLE A: [ID] [Name]
TABLE B: [ID] [TableA.ID] [intValue] [intTypeID]

There are 3 pieces of information I want:

Total Sum(TableB.intValue)
Sum(TableB.intValue) WHERE intTypeID = 1
Sum(TableB.intValue) WHERE intTypeID = 2

Getting one of those pieces is simple: SELECT a.ID,a.Name,SUM(b.intValue) WHERE a.ID = x GROUP BY a.ID,a.Name

I assume I need some kind of JOIN, but I can't seem to get it..

View 2 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved