Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
SqlCommandBuilder class
Message
De
14/04/2014 04:07:23
 
 
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:
01598563
Vues:
51
Read the docs. The Update command is constructed based on the Select command used by the DataAdapter.

Where do you see it updating fields in the 'WHERE' clause (or the PK) if these are not included in the select statement ?



>>Hi everybody,
>>
>>I am wondering if you're using SqlCommandBuilder class and is there a way to get it generate normal UpdateCommand and not update command that even updates PK column and uses all columns in the where clause?
>>
>>I have this method at present
>>
>>
>>  protected Boolean ProcessDataTable(SqlCommand toSqlCommand, Boolean generateCommands = false)
>>        {
>>            Boolean results = false;
>>
>>            try
>>            {
>>                this.table = new DataTable();
>>                this.adapter = new SqlDataAdapter(toSqlCommand);
>>                this.adapter.SelectCommand = toSqlCommand;
>>                this.adapter.Fill(this.table);
>>                if (generateCommands)
>>                {
>>                    SqlCommandBuilder builder = new SqlCommandBuilder(adapter);
>>                    adapter.UpdateCommand = builder.GetUpdateCommand(true);
>>                }
>>                results = true;
>>            }
>>            catch (Exception ex)
>>            {
>>                results = false;
>>                Logging.LogFormat(2, ex.Message);  // at least log the problem
>>            }
>>
>>            return results;
>>        }
>>
>>The idea is to simulate VFP TableUpdate, so I can set various columns values and then call a method that will automatically update my table. I got this suggestion in C# forum at MSDN, but the UpdateCommand generated is so ugly, that I am wondering if there can be any other approach.
>>
>>Thanks in advance.
>
>So, no suggestions? Nobody uses the same approach?
>
>Thanks in advance.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform