Anonymous asked in Computers & InternetProgramming & Design · 1 decade ago

SQL in Visual Basic I need to calculate a sum and show it in a label or text box?

Creating a program that shows Computer Systems and adds up the different prices

I currently have a query as

Dim SQLstr As String

SQLstr = "Select (mobo_price+cpu_price+ram_price+gpu_price+hdd_price+dvd_drive_price+case_price+psu_price+mouse_price+keyboard_price+os_price+screen_price+tv_price) as Cost from Computers"

adoComputer.RecordSource = SQLstr

and I need it to show this "Select (mobo_price+cpu_price+ram_price+gpu_price+hdd_price+dvd_drive_price+case_price+psu_price+mouse_price+keyboard_price+os_price+screen_price+tv_price) as Cost from Computers" in a label or text box. Could someone please show me how to do that??

2 Answers

  • mark r
    Lv 5
    1 decade ago
    Favorite Answer

    If you want to display the result (rather than the query) then you will need to create a recordset and read the record and then set the text.

    I think you should just be able to create a label and then select cost as the controlSource because the form will be using the SQL for its recordsource.

  • 1 decade ago

    You can ad a label from the tool box in visual basic. Rename the label to lblsql.

    Now use this command in the code where you want to display

    lblsql.text= "Select (mobo_price+cpu_price+ram_price+gpu_pric… as Cost from Computers"

    This will display the text in a label.

    If you want to use a textbox instead of label, then add a textbox

    textbox1.text="Select (mobo_price+cpu_price+ram_price+gpu_pric… as Cost from Computers"

Still have questions? Get your answers by asking now.