Tuesday, February 8, 2011

Get total record count in a varible or label c# asp.net 4.0

Get total record count in a varible or label c# asp.net 4.0
 
<
html xmlns="http://www.w3.org/1999/xhtml">

<

head runat="server">

<title></title>

</

head>

<

body>

<form id="form1" runat="server">

<div>

<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label><br />

<asp:SqlDataSource

ID="SqlDataSource1"

runat="server"

ConnectionString="<%$ ConnectionStrings:smdbConnectionString %>"

SelectCommand="select sum(totcort) totresult, count(*) totl from dbo.SVANSCRT where anusid=@usid ">

<SelectParameters>

<

asp:QueryStringParameter DefaultValue="0" Name="usid" QueryStringField="id" />

</

SelectParameters>

 

</

asp:SqlDataSource>

<

asp:Label ID="Label2" runat="server" Text=""></asp:Label>

<

br />

</div>

</form>

</

body>
</
html>
 

using

System;

using

System.Collections.Generic;

using

System.Linq;

using

System.Web;

using

System.Web.UI;

using

System.Web.UI.WebControls;

using

System.Data.SqlClient;

using

System.Data;

using

System.Configuration;

public

partial class Default3 : System.Web.UI.Page

{

protected void Page_Load(object sender, EventArgs e)

{

DataView dv = (DataView)SqlDataSource1.Select(DataSourceSelectArguments.Empty);

int cortans = (int)dv.Table.Rows[0][0];

int totrec = (int)dv.Table.Rows[0][1];

if (cortans > 0)

{

Label1.Text =

"Correct Answers: " + cortans + " <br> total Questions:- " + totrec;

}

else

{

Label1.Text =

"No products on reorder.";

}

}

}

private string ConnectionString

{

get

{

string connectionString = ConfigurationManager.ConnectionStrings["smdbConnectionString"].ConnectionString;

return connectionString;

}

}

}

No comments: