Log in

View Full Version : Programming vb question


omar_tariq
Oct 19, 2011, 06:36 PM
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=METSDATABASE;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
//

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