.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

Sqldatasource record count

Posted By:      Posted Date: May 22, 2011    Points: 0   Category :ASP.Net


I have read a few threads on displaying the sqldatasource record count on a label, but not successfull yet.

I am working on Visual studio 2010 (asp.net 4.0 with vb) with sqlexpress for database.

I need to display a grid of record count results from a sql table. To start with i am trying with a simple sqldatasource control and a Label on the webpage.

Can anyone guide as to how can i get the desired result?


<%@ Page Language="VB" AutoEventWireup="false" CodeFile="SRreport.aspx.vb" Inherits="SR_2011_SRreport" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <style type="text/css">
            text-decoration: underline;
    <form id="form1" runat="server">
        <span class="style1"><strong>Record in DL-1</strong></span>:
        <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
&nbsp;records<asp:SqlDataSource ID="SqlDataSource1" runat="server" 
            ConnectionString="<%$ ConnectionStrings:Ranjit WebConnectionString %>

View Complete Post

More Related Resource Links

record count in sqldatasource

Hi,   I would like to know how many records are selected in sqldatasource after select command   Thanks

DataBase maximum table record count


Hello Friends,

My requirement is, we have more than 5 database servers, each server lot of databases, each database lot of tables.

 I want show the details


ServerName: abcServer

DatabaseName: xyzDatabase

MaximumRecordsTableName: empTable


In asp or Classic asp.

please anybody help for code and query.


how to split the connection string in asp ?

record count for subquery which is used for INSERT

My current code is like this

Insert into ReportDetail( Partcipantid, Reportid)

      select distinct ParticipantID , 3 from abc   where

        closed = 0 and ( isnull ( primaryphone, '' )

How to get total record count in an OUTPUT Parameter


I couldn't get the total record count in a, in my stored proc, in a given scenario. Please help


My SP looks like this:

create proc RecordCount

       @CustomerID varchar(10),

       @RecCnt int OUTPUT


begin tran

if(CustomerID = 'ABC')

@RecCnt = select count(*) from Customers where CustomerID='ABC'



begin tran


@RecCnt = select count(*) from Customers where CustomerID='XYZ' and TranDate > '05/01/2009'




-- This is how I called my SP

declare @rc int

exec RecordCount 'XYZ', @RecCnt = @rc OUTPUT

select @rc

sql count record problem


if i have a prodcut with product no. and each product is made by many parts with parts no.
now i would like to retrieve data to count how many parts to make a product.
in sql, can i count parts no. by each product no. like belows:

select product_no,parts_name,manufacture_date,(select count(*) from item where product_no=p.product_no) as [No. of items] from prodcut p left outer join item i on p.product_no=i.product_no

but i found that the execution time is too long, is it the right way to count no. of item in each product??

SSAS - MDX - need to generate a count for the life of a record



I'm struggling trying to create a calculation which will show what I want.  My requirement is to show a count of 1 while a record is active, and 0 when it is not.  For example, in my data warehouse I have an enrollment record active from 1/1/2010 through 12/31/2010 (12 months).  If the user runs an excel cube report for 2010 by months, I want to show a 1 for all 12 months (if the report were run for quarters, then a 1 for each quarter etc.).  If the user runs a report from 2008 through 2010, the record would show 0 for 2008 and 2009.


Now I could haul off and create a daily record for that enrollment, and have 365 daily records in my DB.  I really don't want to do that. Conceptually here's what I want to accomplish:


IIF([Coverage Start Date].[Date].CurrentMember.FirstChild>=[Coverage Start Date].[Calendar Date] AND [Coverage Start Date].[Date].CurrentMember.FirstChild <= [Coverage End Date].[Calendar Date],1,0)


So if the current member in the example above is Q3 2010, then [Coverage Start Date].[Date].CurrentMember.FirstChild would be '7/1/2010' (first day of Q3).  Since 7/1 is >= 1/1 [Coverage Start Date].[Calendar Date] and <= 12/31 [Coverage End Date].[Calendar Date] this should evaluate to 1.


it doesn't. I ge

Unable to Export to Spreadsheet in SharePoint if record Count increase more than 1100


Hi All,

When I am trying to export the SharePoint View from SharePoint site to Spreadsheet, sometimes I am able to export the the whole data and sometimes I only get Column headers but no data or records

I have Infopath form (2007) published on SharePoint Site and I am using MOSS 2007 and Excel 2003

I am not able reach the cause of this behaivour of Export to Spreadsheet functionality

Is their a Buffer size Issue with IIS or Session time out

I am not sure because when I export to Spreadsheet and if the record goes to Spreadsheet the file size is just 1.72 MB

Please suggest

Hitesh Duggal

display a record count from sql database connection


sometimes learning asp.net feels so heavy handed compared to some of the general purpose scripting languages like php.  for examples, all i want to do is create a sql connection that pulls a row count and displays that number.  I don't need a grid, list, detail page, etc., nothing this heavy... a simply query that will display a simple bit of text.  for the life of me I can't figure out how to do it.  Using these controls, I'm not in the code behind with the query, so I wouldn't attach this to a label (or would i), and there's nothing i see in the toolbox that does what i want.  Perhaps i'm too accustomed to php but it feels like with asp.net, major things are simple, and simple things are hard.  any help would be appreciated.  i'm trying to convert my career to c#.net

Record Count on MERGE Statement on Insert,Update,Delete


HI All,

How can I get the numbers of records affected in the Merge statement, INSERT,UPDATE,DELETE  separately and store it in a variable so I can get it in the application side? 



khrizz tell

GridView inline Master/Detail record display

This code drop is part of a smash and grab series. If you're in a rush, you can just grab this code and insert it into your application, no understanding is required. When you have some time (ya, right) you may want to review the source code.

Get Top 1 Record from Dataset

Many of them in need of getting the Top 1 or Top 10 records from a Dataset without going to SQL query. It is possible to do from Code Behind. I have given the code below,
The below code is to get single record from a Dataset. Also I have given for getting 8 records at Green Color.

Enterprize library 4.1 getting output parameter after adding record in db, plz guide



I need to get output parameter (flag) from db after saving record in database. I am using Microsoft Enterprise Library 4.1 for DB. I am inserting record using I Data reader.

Please guide


Gridview Edit on Searching of Record


using Asp.net c#

sql server

i am searching a record from my database and displaying it in gridview now i want the comments should be updated as per the record which is being searched

For E.g if record No.3 is searched then only i can update record no.3 and i don't want rest of data to be shown

now what is happening when i click on edit my whole table is being displayed

this is bcuz i made one method gridfill() which i m calling everytime if i m doing grid row editing,row cancelling and row updating

how i can resolve this thing

my code

 protected void GridView2_RowEditing(object sender, GridViewEditEventArgs e)
        GridView2.EditIndex = e.NewEditIndex;


 protected void GridView2_RowUpdating(object sender, GridViewUpdateEventArgs e)
        string id = GridView2.Rows[e.RowIndex].Cells[0].Text;
        TextBox t;
        t = (TextBox)GridView2.Rows[e.RowIndex].Cells[2].Controls[0];
        string query = "update user1 set comments=@comments where id=@id";
        SqlConnection con = new SqlConnection(connstr);
        SqlCommand cmd = new SqlCommand(query, con);

Does this look correct for saving a file/ new record to a database


So thank you for all your help so far, So I think i got this right,
but would like for you all to look it over to see if there is any
areas I might run into trouble with:

//using asp.net mvc 2
the table (sql server 2005, using entities framework)
table fields
"Pattern_Media_GUID  uniqueid 
"Pattern_GUID  uniqueid
"Media varbinary(max)  
"height int
"Width int
"Media_Type String (50)

the form:
<h2> Add Media to this pattern</h2>
<% Html.EnableClientValidation(); %>
<% Html.BeginForm("AddMedia", "Pattern", new { id= Model.Pattern_Guid} , FormMethod.Post, new {enctype = "multipart/form-data"}); %>
    <%: Html.Label("height") %>
    <%: Html.TextBox("height") %>

    <%: Html.Label("width") %>
    <%: Html.TextBox("width") %>

    <%: Html.Label("Media") %>
    <input type="file" id="Media" name="Media" />
    <input type="submit" name=

Why show only one record?



// Update these variables to values whatever you are storing in your table
        // If you are storing as CARD NUMBER, update this Card Number Attribute Name to CARD NUMBER
        string strCardNumberAttributeName = "Credit card number";
       // string strCardTypeAttributeName = "1";
        string strExpiryDateAttributeName = "Expiry date";
        DataTable dtPaymentDetails = new DataTable();

        string queryString = "SELECT tbl_Payments.PaymentId, tbl_PaymentDetails.AttributeName, tbl_PaymentDetails.Value, tbl_Payments.PaymentType FROM tbl_Payments INNER JOIN tbl_PaymentDetails ON tbl_Payments.ID = tbl_PaymentDetails.PaymentId WHERE ATTRIBUTENAME IN ('" + strCardNumberAttributeName +
                                   "','" + strExpiryDateAttributeName + "') ORDER BY PaymentId";

        string connectionString = "data source=.\\SQLEXPRESS;Integrated Security=SSPI;" +
                                           "AttachDBFilename=|DataDirectory|\\BurnbetDatabase.mdf;User Instance=true";
        using (SqlConnection connection = new SqlConnection(connectionString))
            SqlCommand command = new SqlCommand(queryString, connection);
            SqlDataReader reader = command.ExecuteR

Can this code be setup to run against the whole database instead of just 1 record at a time?


We have made some changes to this code to start capturing 1 new field of data and updating it as new records are added. But there is currently about 120,000 records more or less.. those records of course dont have the new field populated with anything..

We would like to run this logic that already in place and run it against the tables to update the fields 1 time. I think to make it easier, if it can be setup to expect the "valueTwo" variable, so that we can run it againt the individual codes instead of doing all the records at one time.. there are codes that only have a few records, so it would be best to test initially against the small code group.


            strSqual = "insert into trans (trans_type_name, trans_date,sys_id,mod_user_id,show_ind, remoteCode, techName) values('" & valueTwo & "','" & TransDate & "',"&strSystemID&", 1,'T', '" & dbQuote(strUser) & "', '" & strTechName & "')"        
            'get the new transaction_id out for just inserted alarm   
            strSqual = "select max(transaction_id) as transaction_id from trans"  
            set rst = getStaticRecordSet(strSqual)

Querying a db for existence of a record.


Can someone suggest, what is the best approach using linq to sql to do the following

1. Check if a row exists in a table for a given criteria and...

2. If it exists return a particular field value else return '0'.

ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend