Results 1 to 19 of 19

Thread: creating table

Threaded View

  1. #17
    Hyperactive Member
    Join Date
    Jan 2008
    Location
    Merseyside
    Posts
    456

    Re: creating table

    As a stored procedure

    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%'
    and an example of how you could create the VB code to call it.
    (Place code below in button click event)

    vb Code:
    1. ' Create the connection
    2.             Dim lconn As New SqlConnection("Connection in here")
    3.  
    4.             ' Create the command
    5.             Dim lcommand As New SqlCommand
    6.  
    7.             '  Create the datareader
    8.             Dim lsqlDR As SqlDataReader
    9.  
    10.             Try
    11.  
    12.                 ' If the connection is closed
    13.                 If lconn.State = ConnectionState.Closed Then
    14.  
    15.                     ' Open the connection
    16.                     lconn.Open()
    17.  
    18.                 End If
    19.  
    20.                 ' Set the command text to the name of the stored procedure
    21.                 lcommand.CommandText = "usp_Update_Subjects"
    22.  
    23.                 ' Set the command text to be a stored procedure
    24.                 lcommand.CommandType = CommandType.StoredProcedure
    25.  
    26.                 ' Execute the reader
    27.                 lsqlDR = lcommand.ExecuteReader()
    28.  
    29.             Catch ex As Exception ' Catch the error
    30.  
    31.                 ' Do some error handling in here
    32.  
    33.             End Try
    Last edited by kevchadders; Aug 11th, 2008 at 08:46 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width