As a stored procedure
and an example of how you could create the VB code to call it.Code:CREATE PROCEDURE usp_Update_Subjects AS -- Update RDG UPDATE temps SET RDG = t2.GRADE FROM tbl_Test t2 WHERE temps.IDNO = t2.IDNO AND temps.YR = t2.YR AND t2.SUBJECT LIKE 'RDG%' -- Update LANG UPDATE temps SET LANG = t2.GRADE FROM tbl_Test t2 WHERE temps.IDNO = t2.IDNO AND temps.YR = t2.YR AND t2.SUBJECT LIKE 'LANG%' -- Update MATH UPDATE temps SET MATH = t2.GRADE FROM tbl_Test t2 WHERE temps.IDNO = t2.IDNO AND temps.YR = t2.YR AND t2.SUBJECT LIKE 'MATH%' -- Update MUSIC UPDATE temps SET MUSIC = t2.GRADE FROM tbl_Test t2 WHERE temps.IDNO = t2.IDNO AND temps.YR = t2.YR AND t2.SUBJECT LIKE 'MUSIC%' -- Update ARTS UPDATE temps SET ARTS = t2.GRADE FROM tbl_Test t2 WHERE temps.IDNO = t2.IDNO AND temps.YR = t2.YR AND t2.SUBJECT LIKE 'ARTS%'
(Place code below in button click event)
vb Code:
' Create the connection Dim lconn As New SqlConnection("Connection in here") ' Create the command Dim lcommand As New SqlCommand ' Create the datareader Dim lsqlDR As SqlDataReader Try ' If the connection is closed If lconn.State = ConnectionState.Closed Then ' Open the connection lconn.Open() End If ' Set the command text to the name of the stored procedure lcommand.CommandText = "usp_Update_Subjects" ' Set the command text to be a stored procedure lcommand.CommandType = CommandType.StoredProcedure ' Execute the reader lsqlDR = lcommand.ExecuteReader() Catch ex As Exception ' Catch the error ' Do some error handling in here End Try




Reply With Quote