Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
SqlCommandBuilder class
Message
 
 
À
14/04/2014 12:27:44
Information générale
Forum:
ASP.NET
Catégorie:
ADO.NET
Versions des environnements
Environment:
C# 4.0
OS:
Windows 7
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Web
Divers
Thread ID:
01598513
Message ID:
01598609
Vues:
27
Rob,

Setting all these properties didn't change a thing :( My UpdateCommand is still very long:
UPDATE [dbo].[gst_pass] SET [pass_no] = @pass_no, -- BTW, this is a PK in that table










 [guest_no] = @guest_no, [masterpass] = @masterpass, [swipe_no] = @swipe_no, [addit_no] = @addit_no,
 [wtp_no] = @wtp_no, [rfserial] = @rfserial, [additchar1] = @additchar1, [additchar2] = @additchar2,
 [addit_no2] = @addit_no2, [addit_no3] = @addit_no3, [val_parent] = @val_parent, 
[valprnttyp] = @valprnttyp, [last_use] = @last_use, [printcount] = @printcount,

etc. for about 30 more columns

[a_maxqty6] = @a_maxqty6, [a_trklqty6] = @a_trklqty6, [a_names] = @a_names, 
[mod_op] = @mod_op, [mod_sp] = @mod_sp, [cc_swipe] = @cc_swipe, [pin] = @pin 

WHERE (([pass_no] = @Original_pass_no))
-- where is fixed

Even though I changed the UpdateRows method to be
 public Boolean UpdateRows(Boolean generateCommands = false)
        {
            Boolean results = false;
            try
            {
                if (generateCommands)
                {
                    SqlCommandBuilder builder = new SqlCommandBuilder(adapter);
                    builder.ConflictOption = ConflictOption.OverwriteChanges;
                    builder.SetAllValues = false; // Set only changed values
                    adapter.UpdateCommand = builder.GetUpdateCommand(true);
                }
                adapter.Update(this.table);
                results = true;
            }

            catch (Exception ex)
            {
                results = false;
                Logging.LogFormat(2, ex.Message);  // at least log the problem
            }

            return results;
        }
and I added
 protected Boolean ProcessDataTable(SqlCommand toSqlCommand)
        {
            Boolean results = false;

            try
            {
                this.table = new DataTable();
                this.adapter = new SqlDataAdapter(toSqlCommand);
                this.adapter.SelectCommand = toSqlCommand;
                this.adapter.MissingSchemaAction = MissingSchemaAction.AddWithKey; // Generate PK information
                this.adapter.Fill(this.table);
                
                results = true;
            }
            catch (Exception ex)
            {
                results = false;
                Logging.LogFormat(2, ex.Message);  // at least log the problem
            }

            return results;
        }
Do you see what is missing and why it didn't work for me?

Thanks again.

-------------
Although it did shorten the WHERE clause as I see. But it included all columns in the update, not only the changed values.
If it's not broken, fix it until it is.


My Blog
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform