Ask Me Help Desk

Ask Me Help Desk (https://www.askmehelpdesk.com/forum.php)
-   Visual Basic (https://www.askmehelpdesk.com/forumdisplay.php?f=469)
-   -   Programming vb question (https://www.askmehelpdesk.com/showthread.php?t=605360)

  • Oct 19, 2011, 06:36 PM
    omar_tariq
    Programming vb question
    Hello and good day to all...

    I created a database contains "Down Time" table inside this table there is 'employee number' , 'no material PC' and other columns and now I am programming in Visual Basic 2010 and I want to retrieve all the sum of all values that entered into 'no material PC' column in one text box for all employees who entered a record for this column.

    Thanks a lot I really appreciate your help


    This is my code

    //




    Private Sub LoudData()
    Dim myConnection As SqlConnection
    Dim cmd As SqlClient.SqlCommand
    Dim DR As SqlClient.SqlDataReader
    Dim strQuery As String



    'Loss Time No Material PC

    myConnection = New SqlConnection("server=SHHW0037\METSDATABASE;uid=ME TSDATABASE;pwd=METSDB;database=METS")



    strQuery = ("If EXISTS (SELECT * FROM DownTime WHERE Process ='" TextBox1.Text "' AND Date ='" DateTimePicker1.Value.ToString("MM/dd/yyyy ") "') SELECT NoMaterialPC FROM DownTime WHERE Process ='" TextBox1.Text "' AND Date ='" DateTimePicker1.Value.ToString("MM/dd/yyyy") "'")



    Try

    myConnection.Open()
    cmd = New SqlClient.SqlCommand(strQuery, myConnection)
    DR = cmd.ExecuteReader()
    While DR.Read()

    TextBox3.Text = CStr(DR.GetInt32(0))

    End While
    DR.Close()
    myConnection.Close()
    Catch ex As Exception
    MessageBox.Show(ex.Message)
    End Try

    //
  • Oct 20, 2011, 11:36 PM
    omar_tariq
    Thanks all problem solved I just add sum after SELECT and put a Bracket around the column name

  • All times are GMT -7. The time now is 07:15 AM.