Conventionally ExecuteReader method is used for returning DataReader object.
Which in turn you can use to fill DataTable.
What if you want a DataTable and some return argument from your stored procedure?
One way is explained below.
Your stored procedure will have one OUTPUT parameter , that will give you number returned form database:
CREATE PROCEDURE GETPRODICTS
@Keyword nvarchar(20),
@CNT int OUTPUT
AS
Select * from product where productname like ‘%’ + @Keyword + ‘%’
Select @CNT=count(*) from product where productname like ‘%’ + @Keyword + ‘%’
GO
And in ASP.Net Code should be like:
Int32 intCNT;
DataTable xTbl = new DataTable();
using (SqlConnection conn = new SqlConnection(connectionString))
{
SqlCommand cmd= new SqlCommand();
cmd.Connection = conn;
cmd.CommandType= CommandType.StoredProcedure;
cmd.CommandText = “GETPRODUCTS”;
SqlParameter[] tmpParam = new SqlParameter[] {
new SqlParameter(“@keyword”, SqlDbType.NVarChar,20),
new SqlParameter(“@CNT”, SqlDbType.Int)};
tmpParam [0].Value =”test”;
tmpParam [1].Direction = ParameterDirection.Output;
cmd.Parameters.Add(tmpParam);
SqlDataReader rdr =cmd.ExecuteReader(CommandBehavior.CloseConnection);
if (rdr.HasRows)
{ xTbl.Load(rdr); }
rdr.Close();
intCNT = int.Parse(cmd.Parameters[1].Value.ToString());
}
Make sure you CLOSE data reader object before retrieving values from parameter.
So here you will get DataTable with records from data base and Integer variable (intCNT) with record count from same table.
Other Technical Stuff from Siddharth:
Show current date using Javascript in web browser(Client side date in web browser
https://siddharthboraniait.wordpress.com/2013/09/11/show-current-date-using-javascript-in-web-browserclient-side-date-in-web-browser
How to make custom Task Scheduler in asp.net c# using thread
https://siddharthboraniait.wordpress.com/2013/09/06/howto-make-custom-task-scheduler-in-asp-net-csharp-using-thread
Introduction to Andriod – First step towards Andriod application development
https://siddharthboraniait.wordpress.com/2011/07/18/know-andriod-introduction-to-andriod
22.303894
70.802160