Datagridview Updation at run-time

This resource provide the sample of updating the datagridview at run-time using code (SQL query). This is an easy technique for updating it. Many project requires this facility in their project to update data at run time so this can be easily used.

Data Gridview Updation at run-time

Many times it is possible that data gridview cannot be updated with the use of


Where da is sqldataAdapter and ds as Dataset.

For solving such problem, this sample contains an easy way to update data gridview at run-time.

Here SQL query is used for updating the content of data gridview.

code is given below:-

Imports System.IO
Imports System.Data.SqlClient

Public Class Form1

Dim str As String = "PATH OF DATABASE"
Dim scon As SqlConnection
Dim scom As SqlCommand
Dim sql As String
Dim sda As SqlDataAdapter
Dim sds As DataSet
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
scon = New SqlConnection(str)
sql = "select *from info"
scom = New SqlCommand(sql, scon)
sda = New SqlDataAdapter(scom)
sds = New DataSet

DataGridView1.DataSource = sds.Tables(0)
End Sub

Private Sub DataGridView1_CellEndEdit(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellEndEdit
Dim i As Integer
i = DataGridView1.CurrentRow.Index
scon = New SqlConnection(str)
sql = "update info set sname='" & DataGridView1.Item(1, i).Value & "',mob=" & DataGridView1.Item(2, i).Value & " where id=" & DataGridView1.Item(0, i).Value & ""
scom = New SqlCommand(sql, scon)
End Sub
End Class

Thanks and Regards,
Dhiraj Solanki


  • Datagridview Updation at run-time (44716-23642-Datagridview-Updation-at-run-time.rar)
  • Comments

    No responses found. Be the first to comment...

  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name: