Is SqlCommandBuilder the best way?

  • Thread starter Thread starter Mike Klaene
  • Start date Start date
M

Mike Klaene

Being a UNIX guy migrating to the .NET world, I am trying to come to
grips with ADO.NET from C#.

Connecting to the SQL Server and reading in the selected data item, in
this case operator and control row, was quite easy. Now I wish to simply
update the record to say indicate that this operator is "logged on" as
of the current date/time.

Only a single row from the table is in the DataSet. The date/time is
updated. It works using the SqlCommandBuilder. Is there a better way?

Thanks,

Mike
..
 
The commandbuilder is probably 'ok' in this context but in general is
something you want to avoid. Bill Vaughn wrote about it in depth .
www.betav.com -> Articles -> MSDN - Weaning developers from the
CommandBuilder. For this scenario - it's inefficient compared to using the
ExcecuteNonQuery method of your SqlCommand- but it does give you simplicity.
All in all, I'd opt against it.
 
I usually like to look at it as .. "You know a ferrari is better than a
honda, but still you buy a honda". So, it really depends on your situation.
If it works - then don't worry. :)

CommandBuilder has a few downsides, especially around performance, being a
one size fits all - dumb kinda approach, permissioning issues (SQL2k
atleast), etc. But in your case, as Bill Ryan mentioned - you're probably
allright.

- Sahil Malik [MVP]
ADO.NET 2.0 book -
http://codebetter.com/blogs/sahil.malik/archive/2005/05/13/63199.aspx
 
Mike,

I would use in this situation the command.sqlnonquery as Bill already
mentioned with a very short update SQL string.

Setting 'the time' and a boolean as you wrote in a single data base table
row is the only operation that has to be done. Therefore in this case is
using the dataadapter in my opinion a waste of time and resources. (Because
it is probably only a row that belongs to one user you can even not have
concurrencyproblems, although I am curious how you handle this if the user
is already logged on with another computer).

Be as well aware that the update does only update the database, not the
dataset and/or datatable.

I hope this helps,

Cor
 
Back
Top