1

I have project where i want to use the sqlcommandbuilder.

My only problem is that i can not find a decent example of how to use it, or just simply does not understand why it is used like that.

I am building my application based on 3-tier architecture.

Lets say for instance i want to generate a update statement. where does the commandbuilder get the value from to update into the database. i am currently using the normal sqlcommand and manually creates every sql statement. but tends to be a hassle due to multiple database tables, and it gets confusing.

This is for my final project for my software engineering subject. Please need help.

  • 1
    You should consider stored procedures instead of hard-coded update statements :) Other than that, http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlcommandbuilder.aspx – FlyingStreudel Aug 01 '11 at 19:54
  • Are your required to use that technology? If not you may want to look at entity framework or nhibernate. – alun Aug 01 '11 at 19:55
  • I think most courses are still in the late 90's. TBH I'm seeing a resurgence of direct DB access as it cuts through the up front cost of ORM technology, so perhaps it's gone full cycle back to the start again. – Deleted Aug 01 '11 at 19:58
  • Indeed. Maybe something like https://github.com/markrendle/Simple.Data would be useful too avoid spending a week reading up on the ORM – alun Aug 01 '11 at 20:01

1 Answers1

2

I second the remarks in the comments above... a good ORM is definitely worth looking at.

http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlcommandbuilder.aspx

Note: the example that MS have there is fairly good actually.

They pretty much say everything I'd have said.

  1. load up the select command
  2. The commandBuilder will generate Update, Insert, and Delete statements
  3. it only auto generates SQL for a single table
  4. if you need anything more than that, you'll need to generate the SQL statements by hand, and then load them into the CommandBuilder.

  5. the command builder works reasonably well with a DataTable, which in turn can be bound to a DataView in ASP.Net.

By contrast, a good ORM (provided your database is supported) such as nhibernate, can generate multi-table updates + give you a degree of database vendor independence.

A good reason to learn it is so that you can answer any questions that come up in MS certification exams, or perhaps when using databases unsupported by your ORM of choice... or maybe your just want to get something up and running quickly.

sgtz
  • 8,849
  • 9
  • 51
  • 91