Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7496511
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T18:38:53+00:00 2026-05-29T18:38:53+00:00

I have a problem refreshing a DataGridView control after Insert or Update . The

  • 0

I have a problem refreshing a DataGridView control after Insert or Update. The source code:

Get all rows from table in datatable and set to the datasource:

Dim dt1 as DataTable = GetData("SELECT * FROM CLAIMSTATE ")
dataGrid.DataSource = dt1

Update Event if ID is valued, and Insert if it isn’t:

Private Sub dataGrid_RowLeave(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dataGrid.RowLeave

Dim row As DataGridViewRow = CType(sender, DataGridView).Rows(e.RowIndex)
  Dim query As New StringBuilder("")
  If row.Cells(0).Value & "" = "" Then
    query.Append("INSERT INTO CLAIMSTATE ")
    query.Append("(CST_CODE, CST_LABEL, CST_POINTS)")
    query.Append("VALUES ")
    query.Append("(?, ?, ?)")
  Else
    query.Append("Update CLAIMSTATE ")
    query.Append("SET CST_CODE = ?, ")
    query.Append("CST_LABEL = ?, ")
    query.Append("CST_POINTS = ? ")
    query.Append("WHERE CST_ID = ? ")
  End If
  Dim command As New OdbcCommand(query.ToString(), con)
  command.Parameters.Add("@cst_code", OdbcType.Char).Value = row.Cells(1).Value
  command.Parameters.Add("@cst_label", OdbcType.NVarChar).Value = row.Cells(2).Value
  command.Parameters.Add("@cst_points", OdbcType.Decimal).Value = row.Cells(3).Value
  command.Parameters.Add("@cst_id", OdbcType.BigInt).Value = row.Cells(0).Value

  Dim res As Integer = ExecuteNonQuery(command)
End Sub

Public Function GetData(ByRef sqlQuery As String) As DataTable
    Dim command As New OdbcCommand(sqlQuery, con)
    Try
      If con.State = ConnectionState.Closed Then
        con.ConnectionString = conString
        con.Open()
      End If
      Using dr As OdbcDataReader = command.ExecuteReader()
        Dim dt As New DataTable()
        dt.Load(dr)
        Return dt
      End Using
      'con.Close()
    Catch ex As Exception
      MsgBox(ex.Message)
      con.Close()
      Return Null
    End Try
  End Function

Public Function ExecuteNonQuery(ByRef command As OdbcCommand) As Integer
Dim result As Integer = 0
If con.State = ConnectionState.Closed Then
  con.ConnectionString = conString
  con.Open()
End If
'Dim command As New OdbcCommand(sqlQuery, conn)
Try
  'command.Connection = con
  'Dim cmd As New OdbcCommand( sqlQuery, conn)
  result = command.ExecuteNonQuery()
Catch
  result = 0
  If con IsNot Nothing Then
    con.Close()
    command.Dispose()
  End If
Finally
  command.Dispose()
End Try
Return result
End Function

I tried to get all records from the table and set the datasource again at the end of the method but it doesn’t work.

If I put the code:

dataGrid.Rows.Clear()
dataGrid.Columns.Clear()
dt1 = GetData("SELECT * FROM CLAIMSTATE ")
dataGrid.DataSource = dt1

on end of event method RowLeave I recive this error:

“Operation is not valid because it results in a reentrant call to the
SetCurrentCellAddressCore function”

on dataGrid.Rows.Clear(), but if I remove the line codes Rows.Clear() and Columns.Clear(), the debug cursor after execute dataGrid.DataSource = dt1 return to begin of event method an execute some code again and after I recive the some error “…reentrant call to the SetCurrentCellAddressCore function”!

Help me, please!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T18:38:56+00:00Added an answer on May 29, 2026 at 6:38 pm

    For solving this problem I use OdbcDataAdapter. I save all changes with adapter.Update(dataTable) and after I fill the datatable again: adapter.fill(dataTable).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hi I'm having problem refreshing my listview after Async operation. I have a simplecursoradapter,
I have problem with return statment >.< I want to store all magazine names
I have problem compilin this code..can anyone tell whats wrong with the syntax CREATE
I have problem when I try insert some data to Informix TEXT column via
I have problem creating new instance of excel 2007 using VBA (from Access 2002).
i have problem with autorotate on iphone i set up in all classes -
Currently I have a DataGridView in my app which I fill from my Linq-to-SQL
I using multilanguage solution from this thread Multilanguage in WPF But i have problem
We got a MVC project running and we seem to have problem refreshing .less
Possible References I have found a similar problem: Refreshing a SQL database connection which

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.