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

  • SEARCH
  • Home
  • 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 7787065
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T20:32:52+00:00 2026-06-01T20:32:52+00:00

I’m using Visual C# Studio 2010 express and have been trying to batch update

  • 0

I’m using Visual C# Studio 2010 express and have been trying to batch update my table. Everytime that I try to update 1 record I get “Concurrency violation: the UpdateCommand affected 0 of the expected 1 records.” I asked this question at dream in code but I have been a little dissapointed in some of the responses to some honest questions. Link to my question at D.I.C

I took that last suggestions and changed my code to affect the dataset..or so I think but i am getting the concurrent issue still. Here is my updated code.

        private void SendNewPotentialsToZoho()
    {
        Console.WriteLine("Trying to send potentials to Zoho");

        var newZoho = potentialDatabaseDataSet.Potential.DefaultView;
        var poster = new ZohoPoster(ZohoPoster.Fields.Potentials, ZohoPoster.Calls.insertRecords);
        var count = 0;

        //newZoho.RowFilter = "IsNull(ZohoID,'zoho') = 'zoho'";
        newZoho.RowFilter = "Soid = 1234";
        poster.Debugging = !UseZoho;
        for (int i = 0; i < 1; i++)//newZoho.Count; i++)
        {
            var xmlString = Potential.GetPotentialXML(newZoho[i][1], newZoho[i][2], newZoho[i][4], newZoho[i][3], newZoho[i][5], newZoho[i][7], newZoho[i][0]);
            Console.WriteLine("Sending New Records to Zoho: {0}", xmlString);
            poster.PostItem.Set("xmlData", xmlString);
            var result = poster.Post(3);
            Console.WriteLine(result);
            if (!string.IsNullOrEmpty(result))
            {
                try
                {
                    var rowLength = newZoho[i].Row.ItemArray.Length;
                    var rowOffset = Math.Abs((int)newZoho[i][rowLength - 1])-1;

                    potentialDatabaseDataSet.Potential.Rows[rowOffset]["ZohoID"] = ReadResult(result);
                    potentialTableAdapter.Update(potentialDatabaseDataSet.Potential.Rows[rowOffset]);
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Failed to update: {0}", ex.Message);
                }
            }
        }
    }

The bit variable called poster works great. it returns a xml like result that has my zohoID which I parse out and try to store. For testing purposes I try to update only one record. I get the error with potentialTableAdapter.Update(potentialDatabaseDataSet). What is strange to me is that I use a very similar code to make a brand new record and it works great. Infact it is how I made the row with Soid = 1234. I am the only one that has access to this program and as far I know it is not multithreaded so I just don’t understand why it is having concurrency issues. Please help 🙂

EDIT

Ok so I was playing around with it some and found that if I add a EndEdit to it I dont get the concurrent issue. On the flip side though Although my bound datagridview shows the updated data, the data doesn’t actually get updated. So it’s not that i’m back to square one I think i am actually rather close. I’m going from memory on this small bit of code so don’t hate if it isn’t right..it’s mainly for an idea of what i’m talking about

        for (int i = 0; i < 5; i++) //emailRecord.Count; i++)
        {
            if (ZohoEmail.EmailExpectedShipping(emailRecord[i], "12/10/2012"))
            {//true means that the email went through just fine
                try
                {
                    var rowLengh = emailRecord[i].Row.ItemArray.Length;
                    var rowOffset = Math.Abs((int)emailRecord[i][rowLengh - 1]) - 1;

                    potentialDatabaseDataSet.Potential.Rows[rowOffset][17] = true; //17 is Expected Email
                    potentialDatabaseDataSet.Potential.Rows[rowOffset].AcceptChanges();
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Failed to update: {0}", ex.Message);
                }
            }
            potentialTableAdapter.Update(potentialDatabaseDataSet.Potential);
        }

    }
  • 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-06-01T20:32:54+00:00Added an answer on June 1, 2026 at 8:32 pm

    Well I think i figured it out. Thank you very much Marcin for helping me so much on this problem of mine. You were right with the problem being in my generated table adapter. I ended up making my own based on what the autogenerated code was. Here is my code just incase anyone else is having problem with Autogenerated code.

    using System;
    using System.Data.SqlServerCe;
    using System.Data.Common;
    using System.Data;
    
    namespace Zoho
    {
        public partial class PotentialTableAdapter
        {
            SqlCeDataAdapter _adapter;
            SqlCeConnection _connection;
            SqlCeTransaction _transaction;
            SqlCeCommand[] _commandCollection;
            DataTable _table;
    
            public PotentialTableAdapter()
            {
                ClearBeforeFill = true;
                InitConnection();
                InitAdapter();
                InitCommandCollection();
                FillTable();
            }
    
            public bool ClearBeforeFill {get; set;}
            public SqlCeDataAdapter Adapter
            {
                get
                {
                    if ((this._adapter == null))
                    {
                        this.InitAdapter();
                    }
                    return this._adapter;
                }
            }
            public SqlCeConnection Connection
            {
                get
                {
                    if (_connection == null)
                        InitConnection();
                    return _connection;
                }
            }
            public SqlCeTransaction Transaction
            {
                get
                {
                    return _transaction;
                }
                set
                {
                    _transaction = value;
                    for (int i = 0; (i < CommandCollection.Length); i = (i + 1))
                    {
                        CommandCollection[i].Transaction = value;
                    }
                    Adapter.DeleteCommand.Transaction = value;
                    Adapter.InsertCommand.Transaction = value;
                    Adapter.UpdateCommand.Transaction = value;
                }
            }
            public SqlCeCommand[] CommandCollection
            {
                get
                {
                    if ((this._commandCollection == null))
                    {
                        InitCommandCollection();
                    }
                    return this._commandCollection;
                }
            }
            public DataTable Table
            {
                get
                {
                    if (_table == null)
                        FillTable();
                    return _table;
                }
            }
    
        }
    }
    using System.Data.Common;
    using System.Data.SqlServerCe;
    using System.Data;
    
    namespace Zoho
    {
    
        partial class PotentialTableAdapter
        {
                                        private void InitAdapter()
        {
            this._adapter = new SqlCeDataAdapter();
            this._adapter.TableMappings.Add(GetTableMapping());
            this._adapter.SelectCommand = new SqlCeCommand("SELECT * FROM Potential", Connection);
            this._adapter.InsertCommand = GetCommand(@"INSERT INTO [Potential] ([Soid], [SalesRep], [Account], [ClosingDate], [Amount], [Stage], [SourceId], [Product], [FirstName], [Email], [CustomerPO], [ZohoID], [WorkOrder], [ExpectedShip], [TrackingNumber], [DependencyID], [ProcessEmail], [ExpectedEmail], [ShippedEmail]) VALUES (@p1, @p2, @p3, @p4, @p5, @p6, @p7, @p8, @p9, @p10, @p11, @p12, @p13, @p14, @p15, @p16, @p17, @p18, @p19)");
            this._adapter.UpdateCommand = GetCommand(@"UPDATE [Potential] SET [Soid] = @p1, [SalesRep] = @p2, [Account] = @p3, [ClosingDate] = @p4, [Amount] = @p5, [Stage] = @p6, [SourceId] = @p7, [Product] = @p8, [FirstName] = @p9, [Email] = @p10, [CustomerPO] = @p11, [ZohoID] = @p12, [WorkOrder] = @p13, [ExpectedShip] = @p14, [TrackingNumber] = @p15, [DependencyID] = @p16, [ProcessEmail] = @p17, [ExpectedEmail] = @p18, [ShippedEmail] = @p19 WHERE (([NCPotentialKey] = @p20))");
        }
                        private void InitConnection()
        {
            this._connection = new SqlCeConnection(Zoho.Properties.Settings.Default.PotentialDatabaseConnectionString);
        }
                            private void InitCommandCollection()
        {
            _commandCollection = new SqlCeCommand[1];
            _commandCollection[0] = new SqlCeCommand("SELECT * FROM Potential", Connection);
    
        }
                            private void FillTable()
        {
            _table = new DataTable();
            Adapter.Fill(_table);
        }
    
                                                                                                                    private DataTableMapping GetTableMapping()
        {
            var tableMapping = new DataTableMapping();
    
            tableMapping.SourceTable = "Table";
            tableMapping.DataSetTable = "Potential";
            tableMapping.ColumnMappings.Add("Soid", "Soid");
            tableMapping.ColumnMappings.Add("SalesRep", "SalesRep");
            tableMapping.ColumnMappings.Add("Account", "Account");
            tableMapping.ColumnMappings.Add("ClosingDate", "ClosingDate");
            tableMapping.ColumnMappings.Add("Amount", "Amount");
            tableMapping.ColumnMappings.Add("Stage", "Stage");
            tableMapping.ColumnMappings.Add("SourceId", "SourceId");
            tableMapping.ColumnMappings.Add("Product", "Product");
            tableMapping.ColumnMappings.Add("FirstName", "FirstName");
            tableMapping.ColumnMappings.Add("Email", "Email");
            tableMapping.ColumnMappings.Add("CustomerPO", "CustomerPO");
            tableMapping.ColumnMappings.Add("ZohoID", "ZohoID");
            tableMapping.ColumnMappings.Add("WorkOrder", "WorkOrder");
            tableMapping.ColumnMappings.Add("ExpectedShip", "ExpectedShip");
            tableMapping.ColumnMappings.Add("TrackingNumber", "TrackingNumber");
            tableMapping.ColumnMappings.Add("DependencyID", "DependencyID");
            tableMapping.ColumnMappings.Add("ProcessEmail", "ProcessEmail");
            tableMapping.ColumnMappings.Add("ExpectedEmail", "ExpectedEmail");
            tableMapping.ColumnMappings.Add("ShippedEmail", "ShippedEmail");
            tableMapping.ColumnMappings.Add("NCPotentialKey", "NCPotentialKey1");
    
            return tableMapping;
    
        }
                                                private SqlCeCommand GetDeleteCommand()
        {
            var deleteCommand = new SqlCeCommand();
            deleteCommand.Connection = this.Connection;
            deleteCommand.CommandText = "DELETE FROM [Potential] WHERE (([NCPotentialKey] = @p1))";
            deleteCommand.CommandType = CommandType.Text;
            var parameter = new SqlCeParameter("@p1", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, "NCPotentialKey", DataRowVersion.Original, null);
            deleteCommand.Parameters.Add(parameter);
    
            return deleteCommand;
        }
            private SqlCeCommand GetCommand(string text)
            {
                var command = new SqlCeCommand(text);
                command.Connection = this.Connection;
                command.Parameters.Add(new SqlCeParameter("@p1", SqlDbType.Int, 0,      ParameterDirection.Input, true, 0, 0, "Soid",          DataRowVersion.Current, null));
                command.Parameters.Add(new SqlCeParameter("@p2", SqlDbType.NVarChar, 0, ParameterDirection.Input, true, 0, 0, "SalesRep",      DataRowVersion.Current, null));
                command.Parameters.Add(new SqlCeParameter("@p3", SqlDbType.NVarChar, 0, ParameterDirection.Input, true, 0, 0, "Account",       DataRowVersion.Current, null));
                command.Parameters.Add(new SqlCeParameter("@p4", SqlDbType.NVarChar, 0, ParameterDirection.Input, true, 0, 0, "ClosingDate",   DataRowVersion.Current, null));
                command.Parameters.Add(new SqlCeParameter("@p5", SqlDbType.Money, 0,    ParameterDirection.Input, true, 0, 0, "Amount",        DataRowVersion.Current, null));
                command.Parameters.Add(new SqlCeParameter("@p6", SqlDbType.NVarChar, 0, ParameterDirection.Input, true, 0, 0, "Stage",         DataRowVersion.Current, null));
                command.Parameters.Add(new SqlCeParameter("@p7", SqlDbType.Int, 0,      ParameterDirection.Input, true, 0, 0, "SourceId",      DataRowVersion.Current, null));
                command.Parameters.Add(new SqlCeParameter("@p8", SqlDbType.NVarChar, 0, ParameterDirection.Input, true, 0, 0, "Product",       DataRowVersion.Current, null));
                command.Parameters.Add(new SqlCeParameter("@p9", SqlDbType.NVarChar, 0, ParameterDirection.Input, true, 0, 0, "FirstName",     DataRowVersion.Current, null));
                command.Parameters.Add(new SqlCeParameter("@p10",SqlDbType.NVarChar, 0, ParameterDirection.Input, true, 0, 0, "Email",         DataRowVersion.Current, null));
                command.Parameters.Add(new SqlCeParameter("@p11",SqlDbType.NVarChar, 0, ParameterDirection.Input, true, 0, 0, "CustomerPO",    DataRowVersion.Current, null));
                command.Parameters.Add(new SqlCeParameter("@p12",SqlDbType.NVarChar, 0, ParameterDirection.Input, true, 0, 0, "ZohoID",        DataRowVersion.Current, null));
                command.Parameters.Add(new SqlCeParameter("@p13",SqlDbType.Int, 0,      ParameterDirection.Input, true, 0, 0, "WorkOrder",     DataRowVersion.Current, null));
                command.Parameters.Add(new SqlCeParameter("@p14",SqlDbType.DateTime, 0, ParameterDirection.Input, true, 0, 0, "ExpectedShip",  DataRowVersion.Current, null));
                command.Parameters.Add(new SqlCeParameter("@p15",SqlDbType.NVarChar, 0, ParameterDirection.Input, true, 0, 0, "TrackingNumber",DataRowVersion.Current, null));
                command.Parameters.Add(new SqlCeParameter("@p16",SqlDbType.Int, 0,      ParameterDirection.Input, true, 0, 0, "DependencyID",  DataRowVersion.Current, null));
                command.Parameters.Add(new SqlCeParameter("@p17",SqlDbType.Bit, 0,      ParameterDirection.Input, true, 0, 0, "ProcessEmail",  DataRowVersion.Current, null));
                command.Parameters.Add(new SqlCeParameter("@p18",SqlDbType.Bit, 0,      ParameterDirection.Input, true, 0, 0, "ExpectedEmail", DataRowVersion.Current, null));
                command.Parameters.Add(new SqlCeParameter("@p19",SqlDbType.Bit, 0,      ParameterDirection.Input, true, 0, 0, "ShippedEmail",  DataRowVersion.Current, null));
                command.Parameters.Add(new SqlCeParameter("@p20",SqlDbType.Int, 0,      ParameterDirection.Input, true, 0, 0, "NCPotentialKey",DataRowVersion.Original, null));
    
                return command;
            }
        }
    }
    

    now for my wrapper class. I find this to be rather useful to do it this way.
    using System;
    using System.Data.SqlServerCe;
    using System.Data;

    namespace Zoho
    {
        public class DatabaseConnection
        {
            PotentialTableAdapter table;
            public DatabaseConnection()
            {
                table = new PotentialTableAdapter();
            }
            public DataTable Table
            {
                get
                {
                    return table.Table;
                }
            }
    
            public void Update()
            {
                try
                {
                    Console.Write("Attemping to update database: ");
                    table.Adapter.Update(Table);
                    Console.WriteLine("Success");
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Fail: {0}", ex.Message);
                }
            }
    
        }
    }
    

    and lastly for the snippet of code that actually matters. The one that Marcin helped me figure out. It is super easy actually.

            DatabaseConnection AllPotentials = new DatabaseConnection();
            var newZoho = AllPotentials.Table.DefaultView;
            var poster = new ZohoPoster(ZohoPoster.Fields.Potentials, zohoPoster.Calls.insertRecords);
    
            newZoho.RowFilter = "IsNull(ZohoID,'zoho') = 'zoho'";
            poster.Debugging = !UseZoho; //UseZoho= false which turns debugging on
    
            for (int i = 0; i < 1; i++)//newZoho.Count; i++)
            {
                var xmlString = Potential.GetPotentialXML(newZoho[i]);
                Console.WriteLine("Sending New Records to Zoho: {0}", xmlString);
                poster.PostItem.Set("xmlData", xmlString);
                var result = poster.Post(3);
                Console.WriteLine(result);
                if (!string.IsNullOrEmpty(result))
                {
                    try
                    {
                        newZoho[i].Row["ZohoID"] = ReadResult(result);
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("Failed to update: {0}", ex.Message);
                    }
                }
            }
            try
            {
                Console.Write("Trying to update the database after getting zoho: ");
                AllPotentials.Update(); 
                Console.WriteLine("Success");
            }
            catch (Exception ex)
            {
                Console.WriteLine("Failed: {0}", ex.Message);
            }
    

    I tried it out and it said success so i opened up the database in a different program and low and behold my fake data has the zoho id in it 🙂 i’m so excited. Now I can actually get this program up and running. The only problem I am having now is that in my datagridview it is only showing like 4 or 5 records instead of 201 records (and i just thought about it i bet that filter has soemthign to do with it!). So well time to finish up my program now that it works! 🙂 thank you again Marcin for being patient and helping me out. Since you told me that the problem was in my tableAdapter I am going to mark the question as answered by you.

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

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have thousands of HTML files to process using Groovy/Java and I need to
I'm trying to create an if statement in PHP that prevents a single post
I am trying to loop through a bunch of documents I have to put
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i

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.