Quantcast
Channel: VBForums
Viewing all articles
Browse latest Browse all 15015

VS 2012 Saving DataGridview changes to database

$
0
0
Hi,

I have a DatagridView and I want to save changes to the datagridview to my SQL Server database.

I have the following code:

Code:


Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click       
        Dim path As String
        path = ConfigurationManager.AppSettings("SQLDBPath")
        Dim connectionString As String = path
     

        Dim strSql As String = "SELECT * FROM dbo.b2020Survey"
        Dim dtb As New DataTable
        Using cnn As New SqlConnection(connectionString)
            cnn.Open()
            Using dad As New SqlDataAdapter(strSql, cnn)
                dad.Fill(dtb)
            End Using
            cnn.Close()
        End Using
        DataGridView1.DataSource = dtb
     
        dtb.AcceptChanges()
 End Sub

I would be very grateful if someone can help me, please.

Ijaz

Viewing all articles
Browse latest Browse all 15015

Trending Articles



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