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


Similar Messages:

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

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 :: 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 Use SqlDataReader To Read The Last Row Added To A Table

Jun 17, 2010

[Code]....

My question is how do i use SqlDataReader to read the last row added to a table getting the contents of a column and storing it as a c# varaible

View 2 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

Data Controls :: Display Data From Database In TextBox Using SQLDataReader

Jan 21, 2014

i'm trying to retrieve the data from a sql query into several textbox and dropdownlist but can't there is my code and it send a ex "Conversation of the string "@ p2" in the "Integer" type is not valid"

Dim con As String = "Select * from tbl_Cotizacion WHERE numCotizacion = " & txt_nGuia.Text
Dim cmd As New SqlCommand(con, conexion)
conexion.Open()
cmd.Connection = conexion

[CODE]...

View 1 Replies

Forms Data Controls :: How To Convert Sqldatareader To List

Jun 28, 2010

how to convert sqldatareader to List

View 2 Replies

Forms Data Controls :: Paging In Datalist - Using A SqlDataReader To Populate

Mar 26, 2010

I need to be able to Page in my Datalist. As you can see from the code below I'm using a SqlDataReader to populate my Datalist.

[Code]....

View 5 Replies

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

Data Controls :: Display Multiple Records From SqlDataReader In Multiline TextBox?

Jun 16, 2015

I am developing a message pool means like a Facebook  when we click on above  message icon all message show in list   .then click on the sender name all message show that person. For

That kind of message poll am developed two pages one page is sender and the other one is receiver .when I send message from sender page it will be saved into data base and show into other pages text box.

Now problem is that the receiver pages cannot show all messages .it will show one first message which are saved into database.

I want it will show all messages which are sending from sender page. below my all code. 

WebForm1.aspx.css
using System;
using System.Collections.Generic;
using System.Linq;

[Code].....

View 1 Replies

Forms Data Controls :: See If CheckBox In Populated GridView Is Checked And Compare To SQLDataReader?

May 13, 2010

I'm a little new in ASP.NET, so i don't know how the .NET machine fully works..I'm using two strategies to solve my problem, both invoked by a Button.Click event, but i don't know which one is better..My worries are about the server overload and page load time.This is the regular approuch i've used..

[Code]....

The second one is by using a funtion (named checkIfNumberExistsInDataTable) that does a binary search in a datatable to find a number

conn.Open()
Dim dr As SqlDataReader = cmd.ExecuteReader
Dim da As New DataTable()

[code]...

View 2 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

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

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

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

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

.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

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







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