Sign In| Join
Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Nov 28, 2011 09:10 AM by karthicks
Contributor
2503 Points
2125 Posts
Nov 28, 2011 08:51 AM|LINK
Hi,
I would like to know if there is a way to get the number of results retrieved from Select Query.I want to use the result in my String array size.
Is there a way to do it?
Best Regards.
Here is my sample code:
OracleDataReader myReader = null; try { //Logging log4net.Config.XmlConfigurator.Configure(); String connect = "Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=111.11.11.11)(PORT=1111))(CONNECT_DATA=(SERVICE_NAME=TEST)));User Id=abc;Password=abc"; OracleConnection cn = new OracleConnection(connect); OracleCommand cmd = new OracleCommand(); cn.Open(); cmd.Connection = cn; cmd.CommandText = "select C.TRNS_NO,C.AGN_NO,C.INVOICE_NO,C.REP_AMOUNT from azcbsgw.ic_data c where to_date (c.TRNS_DT, 'DD/MM/YYYY') = '27/11/2011' and c.REP_AMOUNT>0 and c.bnk_cd=3"; //cmd.Parameters.Add("dt", dt); myReader = cmd.ExecuteReader(); string[] queryResult = new string[size from query];
All-Star
32176 Points
5536 Posts
Nov 28, 2011 09:10 AM|LINK
if you want to get count then refer below code
cmd.CommandText ="select count(*) from azcbsgw.ic_data c where to_date (c.TRNS_DT, 'DD/MM/YYYY') = '27/11/2011' and c.REP_AMOUNT>0 and c.bnk_cd=3";
int count= Convert.ToInt32(cmd.ExecuteScalar());
string[] queryResult = new string[count];
else if you want to add the values to string array, you can use ArrayList instead of string array like below
ArrayList al=new ArrayList(); if(myReader.HasRows) while(myReader.Read()) al.Add(myReader["TRNS_NO"]);
cenk1536
Contributor
2503 Points
2125 Posts
How to get the number of results from OracleDataReader?
Nov 28, 2011 08:51 AM|LINK
Hi,
I would like to know if there is a way to get the number of results retrieved from Select Query.I want to use the result in my String array size.
Is there a way to do it?
Best Regards.
Here is my sample code:
karthicks
All-Star
32176 Points
5536 Posts
Re: How to get the number of results from OracleDataReader?
Nov 28, 2011 09:10 AM|LINK
if you want to get count then refer below code
cmd.CommandText ="select count(*) from azcbsgw.ic_data c where to_date (c.TRNS_DT, 'DD/MM/YYYY') = '27/11/2011' and c.REP_AMOUNT>0 and c.bnk_cd=3";
int count= Convert.ToInt32(cmd.ExecuteScalar());
string[] queryResult = new string[count];
else if you want to add the values to string array, you can use ArrayList instead of string array like below
Karthick S