Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
SqlCommandBuilder class
Message
 
 
General information
Forum:
ASP.NET
Category:
ADO.NET
Environment versions
Environment:
C# 4.0
OS:
Windows 7
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Web
Miscellaneous
Thread ID:
01598513
Message ID:
01598585
Views:
52
The SQLCommand I am passing is very simple

select * from myTable where PK = @PK

However, the UpdateCommand I am getting is

update myTable set PkColumn = @PK, OtherColumns = ...
WHERE PkColumn = @OriginalPk and OtherColumns = @OriginalValue
-----------------------------------------------------------------

I actually want to update only certain columns (not all of them) and only based on the PK column. I don't see in the docs how can I influence the Update command the SqlCommandBuilder is building.


>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.
If it's not broken, fix it until it is.


My Blog
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform