ADO.NET :: Get Number Of Returned Rows By Data Reader?

Feb 24, 2011

I have a web page where I want to return number of returned rows by datareader as I need to get Count of rows. My code is as follow :

SqlCommand cm = new SqlCommand(); SqlDataReader dr;sqlconnection cn; public int Returndatareader( int x)
{
int s;
string sqlstr = "SELECT COUNT(*) FROM P_Events as Counter";
cm.CommandText = sqlstr;
cm.Connection = cn;
cn.Open();
dr = cm.ExecuteReader();
if (dr.Read())
{
int y = dr.RecordsAffected;
s = y;
//return y;
}
cn.Close();
return x;
}

but the rows affected count is -1 everytime i run my code.

View 5 Replies


Similar Messages:

Forms Data Controls :: Check Total Number Of Rows Returned From DB When Using Repeater?

Feb 6, 2010

Using C#, how can I check the total number of rows returned from a database when using a Repeater? The reason I need to check is I need to alter the presentation of the data when there is only 1 row returned.

View 9 Replies

Vb.net - Get The Number Of Rows Returned By OleDbDataReader?

Jun 18, 2010

After connecting to a database using DataReader, how can I count the number of rows ?

View 2 Replies

Trying To Get The Number Of Rows Returned In A Query In Visual Basic?

Feb 11, 2010

Trying to get the number of rows returned in a query in Visual Basic.The query returns 3 rows.Dim td As Integer = dataset1.Tables(0).Rows(0).ItemArray(0) has a value of 1.Dim tg As Integer = GridView1.DataSource.tables(0).rows.count has a value of 3.1. Why do aren't they both 3 ?2. Is there a best way of getting the number of rows ?3. Where can I find a tutorial or book that explains the notation above ?

View 3 Replies

Forms Data Controls :: Gridview Row Count / How To Get A Count Of The Number Of Rows That Are Returned

Dec 17, 2010

When a user submits the query to SQL when clicking a button I need to get a count of the number of rows that are returned. Which event does the gridview.count code need to be place in?

Right now I have it in the btn_click event, but in order to get it to count the rows you have to hit the button twice since the query is not returned yet. Here is my code.

[Code]....

View 1 Replies

DataSource Controls :: Count The Number Of Rows Returned From The Database?

Jan 17, 2010

I have executed my query in VB with:

[Code]....

I now want to count the number of returned rows so that I can say:IF rows_returned = 1 then login else deny
I think you get the idea.P.S. I know this is not the most secure method of login but I do not want to use the ASP.NET configuration manager as I like to understand what is happening. I am starting off very simple and I shall work up from there.

View 1 Replies

DataSource Controls :: SQL Select Union And Total Number Of Returned Rows?

May 1, 2010

SQL Select Union and total number of returned rows?

View 3 Replies

Web Forms :: ExecuteReader - No Datagrid Results Returned Since Reader?

Nov 1, 2010

I am having problems with the following. On debugging I find that when strKeywords = '', reader = "System.Data.SqlClient.SqlDataReader". However, as soon as strKeywords takes the value of anything else, reader = nothing. But the stored procedure handles the arguments fine, so I am very confused!

[Code]....

View 3 Replies

Data Controls :: Select Number Of Rows From DropDownList And Add Rows To GridView?

May 7, 2015

I came across a situation where a user selects no of rows from dropdown , depending upon the user input, automatically that no of editable rows should appear to input data...(maximum 8 rows only)

View 1 Replies

Forms Data Controls :: Limiting Number Of Records Returned In XML Feed?

May 18, 2010

Currently I have

dlRSS.DataSource = GetRSSFeed("http://www.foodsafetynews.com/headlines.xml")
dlRSS.DataBind()
Function GetRSSFeed(ByVal strURL As String) As DataTable
'Get the XML data
Dim reader As XmlTextReader = New XmlTextReader(strURL)
'return a new DataSet
Dim ds As DataSet = New DataSet()
ds.ReadXml(reader)
Return ds.Tables(2)
End Function
<asp:DataList ID="dlRSS" runat="server" Width="100%" >
<ItemTemplate>
<strong><p><div><asp:HyperLink ID="TitleLink" runat="server" Text='<%# Eval("title") %>' Target="_blank" NavigateUrl='<%# Eval("link") %>'/></div></p></strong>
<strong><p> <div><asp:Label ID="SubtitleLabel" runat="server" Text='<%# Eval("description") %>' /></div></p></strong>
</ItemTemplate>
</asp:DataList>

But is returning all rows in RSS Feed I would only like top 5 or so

View 1 Replies

Looping Through A Returned Rows In DataTable

Jul 31, 2012

I have as script that runs a stored procedure to fetch a comment along with it's id. There are multiple comments and I want to display them but I am having problem with display all the records. Here is my code:

Using con
Using sda As New SqlDataAdapter()
Try
cmd.Connection = con
Catch ex As Exception
Response.Write("Error" & ex.Message)

[code]...

How do I make it so that the returned results will be like this:

                 6 First Comment

                 7 Second Comment

View 1 Replies

Count Number Of Returned Results And Print To Literal?

Apr 9, 2010

I want to count the number of results results returned by my query and print the number to a literal on the page.How would I do that?

View 2 Replies

SQL Server :: Use Cursor To Loop Through Number Of Records Returned?

Mar 25, 2011

using sql server 2005.

i need to query a table which normally will return multiple records for the id and I need to loop through probably using a cursor and pull values out from each record to make a string.

what is the syntax for this? i've seen cursors using a set number (EX: loop through 5 times) but I need to create a query so that I can loop through once for each row returned from my query.

View 13 Replies

Data Controls :: Display Number Of Rows Was Found

Jul 18, 2012

I have textbox with search button the result it's show , but if there is a way to count how many rows was found were cathing the data  form database. I'm using gridview + ado.net + gridview i handle all the events manually....

protected void btnSearch_Click(object sender, EventArgs e) {
if (txtSearch.Text == "") {
lblMessage.Text = "";
lblMessage.Text = "Empty charchter, Try Again";

[code]....

View 1 Replies

Security :: Filtering The Rows Returned By Membership.GetAllUsers()?

Dec 22, 2010

In our asp.net application, we use Membership.GetAllUsers() in order to allow the administrator work with the site's membership.

Is there a way to filter the rows returned by Membership.GetAllUsers() method? I'd like to be able to have a textbox where (part of) the user's first name / last name is entered and then call GetAllUsers() - or a different method - to get only the users whose name begins with value in the text box.

View 4 Replies

SQL Server :: Desired Rows Not Returned Because Of Null Values

Sep 26, 2010

I have a property table and an image table.

I want this query to return all distinct properties and a thumbnail image. However some properties don't have thumbnail images and they don't get returned by the query. If the imgid is null I still want to return the property. Not sure of how to do this.

[Code]....

[Code]....

View 4 Replies

Forms Data Controls :: Return Number Of Rows In A Dataset?

Jan 14, 2010

I'm using a table adapter to perform my queries. I'm sure I'm missing something really easy, but I can't figure out how to return the number of rows returned from a query to a dataset used for a GridView.Basically, I want to display a message "No records exist for your selection" by testing for ReturnedRows = 0.

Excerpt of C# code:

handoutDSTableAdapters.handoutTableAdapter handoutsAdapter =
new handoutDSTableAdapters.handoutTableAdapter();
gv_Handout.DataSource = handoutsAdapter.GetDataByDoctor(Int32.Parse(ddl_MD.SelectedValue));
gv_Handout.DataBind();

View 4 Replies

Forms Data Controls :: Returning The Number Of Rows From A Table?

Feb 10, 2010

I am trying to follow an example from Lesson #25 of [URL] I am not trying to do paging as the above example is doing. I simply want to do a Query and return the the number of rows back in my code behind.

I have a DAL Typed Dataset with the following Query

SELECT COUNT(*) AS Expr1
FROM Reservation
WHERE (DateUsed = @DateUsed) AND (SiteID = @SiteID)

I have a BLL setup for the above as follows:

[Code]....

[Code]....

[Code]....

View 2 Replies

Forms Data Controls :: Number Of Displayed Rows In A Grid?

May 30, 2010

How to control the number of displayed rows in a grid? Which property to change?

View 2 Replies

Data Controls :: Get Count (Number) Of Rows In GridView Using JavaScript?

May 7, 2015

how to get the length of the gridview rows using javascript?

View 1 Replies

Forms Data Controls :: Limit Number Of Selected Rows In Data Source For GridView?

Apr 30, 2010

I'm sure it was discussed hundred of times, but maybe this time will elucidate some new points )

The question is: do I need to limit number of selected rows in data source for GridView?

When I use paging in GridView does limiting selected rows make GridView work faster?

Now I use ObjectDataSource with Linq in functions.

[Code]....

Does this make sense or I can just use LinqDataSource without thinking of selected rows?

View 2 Replies

Forms Data Controls :: Events And Pageload Not Firing After Datagrid Containing Large Number Of Rows Of Data

Sep 6, 2010

I have a datagrid in aspx page.Inside of datagrid i am using around 15 controls such as Button,dropdownlist and text box

controls.Once the datagrid binds then the events in the aspx page not firing.Issue occured when the number of rows greater than 500.The number of rows less then its works fine.

"Platform i am working on ASP.NET1.1"

View 2 Replies

SqlHelper.ExecuteReader Results Varying And Unexpected When Certain Number Of Records Are Returned?

Jul 4, 2010

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 table for a given callerId.I retrieve the clients from my Controller with the SelectLiveClientsForCaller method. The message is then passed on to the DAL through the static Instance method in the DataProvider class:

public List<Client> SelectLiveClientsForCaller(int callerID)
{
List<Client> results = new List<Client>();

[code]...

View 3 Replies

ADO.NET :: Can't Get Reader.hasrows And Reader.read To Work Together In Code Behind

Feb 22, 2011

I have some code in my vb.net code behind that queries a database, and if there is data, outputs it from the codebehind to a datalist on my asp.net page. In addition to sending the data to the datalist on the page, I need to take the value from "mbillaty" that is returned from the sql query, and have that value be the selected value for a drop down box also on the page. I can get either the datalist to fill, or the selected value for the dropdown box to be selected depending upon which bit of code I place before the other (ARGH), but I can't get them to both work together on the page. What am I doing wrong?

[Code]....

View 2 Replies

Forms Data Controls :: Find Number Of Rows For Repeater Control?

Jan 19, 2010

I'm looking for the correct syntax to get me the last row of a repeater item and use it in a literal below. As you can see I have the item index syntax already. assume that there is a repeater control surrounding the literal already.

I have already bound the data so it will not use obitemdatabound .

<asp:Literal id="Rpt_ItemCount" runat="server"
Text = '<%# (int) DataBinder.Eval(Container, ItemIndex"))%>'></asp:Literal>

View 6 Replies







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