[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 692
  • Last Modified:

C# WinFrom, Row already belongs to another table...

Hi all, code below keeps returning "Row already belongs to another table"

ive googled the error and have tried changing to

Rows.InsertAt
ImportRow

all bring back the same error!

anyone help me out?
DataRow NewMessage = dataSetClients.ClientMessaging.NewRow();
            NewMessage["RecordManager"] = GlobalFunc.UserName;
            NewMessage["Message"] = memoMessage.Text;
            NewMessage["ClientID"] = clientID;
            NewMessage["DateAdded"] = DateTime.Now;
            NewMessage["MessageSource"] = "User";

            dataSetClients dsNewMessage = new dataSetClients();
            dsNewMessage.ClientMessaging.Rows.Add(NewMessage);

            dataSetClientsTableAdapters.ClientMessagingTableAdapter taNewMessage = new dataSetClientsTableAdapters.ClientMessagingTableAdapter();
            taNewMessage.Update(dsNewMessage.ClientMessaging);
            MessageBox.Show("Aparently where updated! LIES!!!!!!");

Open in new window

0
awilderbeast
Asked:
awilderbeast
1 Solution
 
MathiyazhaganCommented:
hope it is not neccassary to use two datasets...just create new dataset as u did:
dataSetClients dsNewMessage = new dataSetClients();
then directly add your new row and update as I attached.hope this helps.
dataSetClients dsNewMessage = new dataSetClients();
DataRow NewMessage = dsNewMessage .ClientMessaging.NewRow();
            NewMessage["RecordManager"] = GlobalFunc.UserName;
            NewMessage["Message"] = memoMessage.Text;
            NewMessage["ClientID"] = clientID;
            NewMessage["DateAdded"] = DateTime.Now;
            NewMessage["MessageSource"] = "User";

                       dsNewMessage.ClientMessaging.Rows.Add(NewMessage);
          dataSetClientsTableAdapters.ClientMessagingTableAdapter taNewMessage = new dataSetClientsTableAdapters.ClientMessagingTableAdapter();
            taNewMessage.Update(dsNewMessage.ClientMessaging);

Open in new window

0
 
awilderbeastAuthor Commented:
that was it!
thanks :)
0

Featured Post

Restore individual SQL databases with ease

Veeam Explorer for Microsoft SQL Server delivers an easy-to-use, wizard-driven interface for restoring your databases from a backup. No expert SQL background required. Web interface provides a complete view of all available SQL databases to simplify the recovery of lost database

Tackle projects and never again get stuck behind a technical roadblock.
Join Now