---
title: "“This row already belongs to this table”"  
description: "“This row already belongs to this table”"  
author: "Lady Bird Johnson"  
published: 2013-06-19  
updated: 2013-06-19  
canonical: https://www.mindstick.com/forum/1212/this-row-already-belongs-to-this-table  
category: "ado.net"  
tags: ["ado.net"]  
reading_time: 2 minutes  

---

# “This row already belongs to this table”

Hi [Expert](https://www.mindstick.com/articles/13120/an-expert-financial-advice-will-improve-your-finances),\
\
I have got “This row [already](https://yourviews.mindstick.com/view/88453/the-hidden-ways-ai-is-already-controlling-your-daily-life) belongs to this table” [error message](https://www.mindstick.com/forum/23174/error-message-the-page-you-are-requesting-cannot-be-served-because-of-the-extension-configuration). Any suggestions always is appreciated. It errors out on my [command](https://www.mindstick.com/blog/178/synchronous-and-asynchronous-command-execution-in-c-sharp-dot-net) button save event. I've listed code for the entire form just to give you an idea on what I'm doing. Hope this helps\
\
[Private](https://www.mindstick.com/blog/11097/java-access-modifiers-the-public-and-the-private-modifiers) Sub btnSave_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSave.Click\
DataGridView1.EndEdit()\
Dim con As [SqlConnection](https://www.mindstick.com/forum/1209/sqlconnection-sqlcommand-sqldatareader-idisposable) = CompDB.GetConnection\
Dim cmd As New System.Data.SqlClient.SqlCommand\
Dim SPgetStandards As [String](https://www.mindstick.com/articles/1527/string-split-in-c-sharp) = "dbo.SPgetStandards"\
Dim SPgetRecordDetail As String = "dbo.SPgetRecordDetail"\
Dim dsStandard As New [DataSet](https://www.mindstick.com/articles/19/dataset)\
Dim dsRecords As New DataSet\
Dim currentrow As DataRow\
Dim currentcolumn As DataColumn\
MsgBox("Record id is " & RecordID)\
Using con\
con.Open()\
Dim Standardsdataadapter As New SqlClient.SqlDataAdapter(SPgetStandards, con)\
Dim Detaildataadapter As New SqlClient.SqlDataAdapter(SPgetRecordDetail, con)\
Detaildataadapter.Fill(dsRecords, "Record")\
Standardsdataadapter.Fill(dsStandard, "[Standard](https://www.mindstick.com/articles/23223/naming-convention-or-coding-standard)")\
\
Figured out how to run a loop through a table and write to the [console](https://www.mindstick.com/blog/210/the-console-class)\
\
For Each currentrow In dsStandard.Tables("Standard").Rows\
For Each currentcolumn In dsStandard.Tables("Standard").Columns\
'Debug.WriteLine(currentrow(currentcolumn) & ControlChars.Tab & ControlChars.Tab)\
'MsgBox(currentcolumn.ToString)\
'Debug.WriteLine(currentrow.Item(0))\
Next currentcolumn\
Next currentrow\
' con.Close()\
'con.Dispose()\
Dim newrow As DataRow = dsRecords.Tables("Record").NewRow\
For Each oRow As DataGridViewRow In DataGridView1.Rows\
If Convert.ToInt16(oRow.Cells("chkbox").Value) = 1 Then\
' Debug.WriteLine("It was clicked ", DataGridView1.Columns.Item(1))\
Debug.WriteLine(oRow.Cells("ID").Value)\
'dsStandard.Tables.Add.Rows("RecordID") = 1234\
'dsRecords.Tables.Add.Rows("Standard_Name_ID") = 1234\
' newrow("Record_Detail_ID") = RecordID\
' newrow("Record_ID") = RecordID\
newrow("Standard_Name_ID") = (oRow.Cells("ID").Value)\
'/////Errors out here!!!!!dsRecords.Tables("Record").Rows.Add(newrow) '/////Errors out here!!!!!\
dsRecords.AcceptChanges()\
End If\
Next\
End Using\
End Sub\
\
Any help on above is really appreciated.

## Replies

### Reply by Sumit Kesarwani

Hi,\
Move this line:\
**Dim newrow As DataRow = dsRecords.Tables("Record").NewRow**\
To be the first line inside of your If block.\


---

Original Source: https://www.mindstick.com/forum/1212/this-row-already-belongs-to-this-table

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
