title: Update table using stored procedure in vb.net
body: <p>i'm having trouble on how do i update my table using datagridview and stored procedure. here is the code;</p>
  
  <pre><code>Private Sub INPUTGrades()
      Dim strConn As String = "Data Source=Jansen;Initial Catalog=SLCBRegistrarDB;Integrated Security=True"
      Dim sqlCon As SqlConnection = New SqlConnection(strConn)
  
      CMD = New SqlCommand
      CMD.Connection = sqlCon
      CMD.CommandText = "PostingofGRADE"
      CMD.CommandType = CommandType.StoredProcedure
  
      CMD.Parameters.AddWithValue("@AcademicYear", cmbAcademicYear.Text)
      CMD.Parameters.AddWithValue("@Period", cmbPeriod.Text)
      CMD.Parameters.AddWithValue("@Section", cmbSection.Text)
      CMD.Parameters.AddWithValue("@CourseCode", cmbSubjectCode.Text)
      CMD.Parameters.AddWithValue("@DescriptiveTitle", cmbDescription.Text)
      CMD.Parameters.AddWithValue("@AcademicLevel", cmbAcadLevel.Text)
  
      CMD.Parameters.Add(New SqlParameter("@StudentID", SqlDbType.Int))
      CMD.Parameters.Add(New SqlParameter("@Grade", SqlDbType.NVarChar))
  
      sqlCon.Open()
      For Each row As DataGridViewRow In dgvSubjectsEntry.Rows
          If Not row.IsNewRow Then
              CMD.Parameters("@StudentID").Value = row.Cells(1).Value
              CMD.Parameters("@Grade").Value = row.Cells(0).Value
  
              Dim RowsAffected As Integer = CMD.ExecuteNonQuery()
              If RowsAffected &gt; 0 Then
                  MsgBox("Grade Successfully Posted.")
              Else
                  MsgBox("Failed!")
              End If
          End If
      Next
      sqlCon.Close()
  End Sub
  </code></pre>
  
  <p>And this is the Stored Procedure:</p>
  
  <pre><code>USE [SLCBRegistrarDB]
  GO
  /****** Object:  StoredProcedure [dbo].[PostingofGRADE]    Script Date: 
  7/21/2017 9:38:16 AM ******/
  SET ANSI_NULLS ON
  GO
  SET QUOTED_IDENTIFIER ON
  GO
  ALTER Procedure [dbo].[PostingofGRADE]
  
  @StudentID Int,
  @AcademicYear nvarchar(50),
  @Period nvarchar(50),
  @Section nvarchar(10),
  @CourseCode nvarchar(50),
  @DescriptiveTitle nvarchar(100),
  @Grade nvarchar(50),
  @AcademicLevel nvarchar(50)
  
  AS
  BEGIN
  
      Declare @AcademicLevelID int
      Declare @SchoolID int
      Declare @TypeofStudentID int
      Declare @CourseID int
      Declare @PeriodID int
      Declare @AcademicYearID int
      Declare @SectionID int
      Declare @SubjectCode int
  
          SELECT @AcademicLevelID=AcadLevelID FROM [Academic Level] WHERE 
  [Academic Level]=@AcademicLevel
  
          SELECT @PeriodID=SemID FROM SemesterList WHERE Description=@Period
  
          SELECT @SectionID=SectionID FROM Section WHERE Section=@Section
  
          SELECT @AcademicYearID=[SY ID] FROM SchoolYear WHERE [School Year]=@AcademicYear
  
   SELECT @SubjectCode=StudentAcademicRecords.[Subject Code]
   FROM         StudentAcademicRecords INNER JOIN
           [Class Schedule LINE] ON StudentAcademicRecords.[Subject Code] = 
   [Class Schedule LINE].SchedID INNER JOIN
           Curriculum ON [Class Schedule LINE].[Subject Code] = Curriculum.
  [Subject Code] INNER JOIN
           ListofSubjects ON Curriculum.SubjectID = ListofSubjects.SubjectID 
   INNER JOIN
           SchoolYear ON StudentAcademicRecords.[Academic Year] = SchoolYear.
   [SY ID] INNER JOIN
           SemesterList ON StudentAcademicRecords.Period = SemesterList.SemID 
  AND Curriculum.SemesterID = SemesterList.SemID
  WHERE        (ListofSubjects.[Course No.] = @CourseCode) AND 
  (ListofSubjects.[Descriptive Title] = @DescriptiveTitle) AND 
           (StudentAcademicRecords.StudentID = @StudentID) AND 
  (SemesterList.Description = @Period) AND (SchoolYear.[School Year] = 
  @AcademicYear)
  
  BEGIN
      UPDATE StudentAcademicRecords
      SET StudentID =@StudentID, [Academic Level] =@AcademicLevelID, Period 
  =@PeriodID, [Academic Year] =@AcademicYearID, Section =@SectionID, [Subject 
  Code] =@SubjectCode, Grade =@Grade
      FROM StudentAcademicRecords
      WHERE [Subject Code]=@SubjectCode AND StudentID=@StudentID
  END
  
  END 
  </code></pre>
  
  <p>If i try to run the code, nothing happens with the table. no changes at all. I tried running in the sql server query, and it works fine but in my vb.net code, it does not.</p>
  
  <p>Any help is appreciated.</p>