Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27357

[RESOLVED] update via datagridview not updating the sql server back-end

$
0
0
Hello again!

I have now another issue with updating sql server with the changes that the user can make in the datagridview.

I have a datagridview that gets populated by a sproc with input params.

Here is the code for the datagridview:

Code:


  Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        Dim results As DataTable = New DataTable()
        Dim connetionString2 As String = "server=SV-MYSERVER;Initial Catalog=Assigned_Sites_Calls_Registry;Integrated Security=SSPI"

        Label37.Text = Now

        Using dbConn As New SqlClient.SqlConnection(connetionString2)
            Using dbCmd As New SqlClient.SqlCommand("sp_HF_populate_DGV_current", dbConn)

                dbCmd.CommandType = CommandType.StoredProcedure ' This is important, this bit me just yesterday. by default, it uses Text as the command type
                dbCmd.Parameters.Add("Hosp_Comm_Name", SqlDbType.NVarChar, 150)
                dbCmd.Parameters.Add("pcp_address_2", SqlDbType.VarChar, 55)
                dbCmd.Parameters.Add("member_address", SqlDbType.VarChar, 150)
                dbCmd.Parameters.Add("Acronym_1", SqlDbType.VarChar, 20)

                dbCmd.Parameters("Hosp_Comm_Name").Value = If(ComboBox1.SelectedIndex > -1, ComboBox1.SelectedValue, DBNull.Value)
                dbCmd.Parameters("pcp_address_2").Value = If(ComboBox2.SelectedIndex > -1, ComboBox2.SelectedValue, DBNull.Value)
                dbCmd.Parameters("member_address").Value = If(ComboBox3.SelectedIndex > -1, ComboBox3.SelectedValue, DBNull.Value)
                dbCmd.Parameters("Acronym_1").Value = If(ListBox1.Text.Length > 0, ListBox1.Text, DBNull.Value)


                'Dim update As New SqlCommand("UPDATE MMLIST_FINAL SET MemberEmail = @MemberEmail, Medical_Record___1 = @Medical_Record___1, InitialLetterSent = @InitialLetterSent, MultipleLettersSent = @MultipleLettersSent, " & _
                '                            " Call_Status = @Call_Status, Appointment_Scheduled = @Appointment_Scheduled, Appointment_Scheduled_Status = @Appointment_Scheduled_Status, FollowUpLetterSent = @FollowUpLetterSent, Reschedule_Appointment = @Reschedule_Appointment, " & _
                '                            " Reschedule_Appointment_Status = @Reschedule_Appointment_Status, Comment = @Comment, Follow_Up_Comment = @Follow_Up_Comment, Updated_By = @Updated_By, Updated_Date = @Updated_Date WHERE tblid = @tblid", dbConn)


                Using dbAdaptor As New SqlClient.SqlDataAdapter(dbCmd)

                    dbAdaptor.Fill(results)

                    DataGridView1.DataSource = results

                    'add row number to the datagridview1
                    Call setRowNumber(DataGridView1)


                End Using

            End Using

        End Using


and this is my code for the update button:

Code:

  Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click

        Try

            Dim results As DataTable = New DataTable()

            cmdBuilder = New SqlCommandBuilder(dbAdaptor)

            changes = ds.GetChanges()


            If changes IsNot Nothing Then

                dbAdaptor.Update(results)

            End If

            MsgBox("Changes Done")

        Catch ex As Exception

            MsgBox(ex.ToString)

        End Try


    End Sub



I've been trying different things that found online, but nothing seems to save to the sql server db.

Thank you for your help in advanced!

Tammy

Viewing all articles
Browse latest Browse all 27357

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>