Click here to Skip to main content
15,886,873 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi, I am trying to get the value from sql query which getting the sum of an specific column. I want it to display on textbox/label so that I could insert it to another table. How can I do this? I am using Oracle.DataAccess. I am trying that ExecuteScalar but it gives me an error. What to do? Thanks! Here is my code:
C#
   eSQl = "SELECT sum(inttotal) FROM tbltrans where                   prj_code='"+txtPrjCod.Text+"' group by prj_code";

 SQLdr = DBCon.show(eSQl);

 while (SQLdr.Read())

 {

   tot = Convert.ToInt32(SQLdr.GetOracleValue(30).ToString());

   textBox1.Text = tot.ToString();

}

SQLdr.Close();
Posted
Updated 15-Nov-12 22:11pm
v2
Comments
Nandakishore G N 16-Nov-12 4:41am    
what is the error?specify it any one can help you..in solving the Question.
Nandakishore G N 16-Nov-12 8:52am    
and specify the datatype..used..for prj_code..May Be that may be prob...bcoz,if the datatype is varchar..then it works..else you have to remove that quotes..check and validate..it

1 solution

Hi,

Please update your query as below.

C#
eSQl = "SELECT sum(inttotal)as TOTAL FROM tbltrans where prj_code='"+txtPrjCod.Text+"'";

Then read value from dr as

C#
while (SQLdr.Read())
{
   tot = Convert.ToInt32(SQLdr.GetOracleValue(0).ToString());
   textBox1.Text = tot.ToString();
}
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900