4 Replies - 7207 Views - Last Post: 16 November 2012 - 11:14 AM Rate Topic: -----

#1 maecy  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 19-February 12

How to get the value of sql (sum) query in textbox?

Posted 15 November 2012 - 11:53 PM

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:
       eSQl = "SELECT sum(DISTINCT 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();



Is This A Good Question/Topic? 0
  • +

Replies To: How to get the value of sql (sum) query in textbox?

#2 Momerath  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1012
  • View blog
  • Posts: 2,444
  • Joined: 04-October 09

Re: How to get the value of sql (sum) query in textbox?

Posted 16 November 2012 - 12:40 AM

What error are you getting?
Where is the ExecuteScalar?
There is no need for the group by clause, since you exclude all other prj_codes
I'm not sure you can use DISTINCT there, or why you'd want to do so.
Was This Post Helpful? 0
  • +
  • -

#3 maecy  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 19-February 12

Re: How to get the value of sql (sum) query in textbox?

Posted 16 November 2012 - 01:54 AM

Thanks for your reply.
Well, when I'm using ExecuteScalar, it gives me errors of invalid arguments, I believe it is from my connection which is from DBConnection.cs. I am looking for other ways to solve this.. But when Im using the code I have given above, it does not give me error but doesnt give me results either.
Was This Post Helpful? 0
  • +
  • -

#4 Michael26  Icon User is offline

  • DIC-head, major DIC-head
  • member icon

Reputation: 362
  • View blog
  • Posts: 1,539
  • Joined: 08-April 09

Re: How to get the value of sql (sum) query in textbox?

Posted 16 November 2012 - 02:05 AM

eSQl = "SELECT sum(DISTINCT inttotal) FROM tbltrans where prj_code='"+txtPrjCod.Text+"' group by prj_code";


This is really bad practice there, learn how to parameterize your query properly

Read up on SQL Injection Attacks. SQL Server will take whatever you give it and execute it. So, it's entirely possible for someone to slip in some malicious SQL into your field, if you're not careful. But parameters take care of all that for you. It escapes SQL syntax, so that all parameter content is treated as a value, never a command.

This post has been edited by Michael26: 16 November 2012 - 02:07 AM

Was This Post Helpful? 0
  • +
  • -

#5 Momerath  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1012
  • View blog
  • Posts: 2,444
  • Joined: 04-October 09

Re: How to get the value of sql (sum) query in textbox?

Posted 16 November 2012 - 11:14 AM

Well I have no idea what objects you are using there, DBConnection doesn't have a method named 'show', so what's going on in line 3 is a mystery. No idea what type of object SQLdr is, or where the number 30 came from in line 5. You need to provide a lot more information if you want help.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1