What's a better way to add a new row to a table:

(1) An Insert SQLCommand object? or;
(2) Through the DataRows collection doing it manually and then calling
Update on the Adapter?

Re: What's the better way to modify rows in a table? by William

William
Wed Aug 31 22:04:26 CDT 2005

It depends.
1) assumes that you hard-code the schema and provide the INPUT arguments as
Parameters in a Command object. This approach is best when you can't depend
on VS or the Command(don't use)Builder to generate the INSERT statement for
you. This is often the case when you return rows from a JOIN, stored
procedure or where the SELECT returns expression columns. It does not take
much to confuse the CommandBuilder.
2) this assumes the CB works. It does in simple cases but it takes an extra
runtime round trip unless you get VS to call it. In this case your code is
just as brittle as when you roll your own INSERT statement.


--
____________________________________
William (Bill) Vaughn
Author, Mentor, Consultant
Microsoft MVP
www.betav.com/blog/billva
www.betav.com
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
__________________________________

"Water Cooler v2" <wtr_clr@yahoo.com> wrote in message
news:1125543135.776870.226420@g47g2000cwa.googlegroups.com...
> What's a better way to add a new row to a table:
>
> (1) An Insert SQLCommand object? or;
> (2) Through the DataRows collection doing it manually and then calling
> Update on the Adapter?
>



Re: What's the better way to modify rows in a table? by Water

Water
Wed Aug 31 22:23:32 CDT 2005

Hmm! It turned out I grabbed the wrong end of my question. I am
re-reading my question and it sounds like I've asked, "to
CommandBuilder or not to CommandBuilder?".

Let me rephrase. What are the differences in the two methods, if any?

(1) Dim Com as SQLCommand("insert into Foo values(1, 'A dingo ate my
baby')")
Call Com.ExecuteNonQuery()

(2) Dim Adap as SQLDataAdapter
Adap.Fill(ds, "Foo")
Dim InsertCommand As SQLCommand = new SQLCommand("insert into Foo
values(@ID, @SomethingElse)")
Dim param As SQLParameter = New SQLParameter

....
.....
Adap.Update(ds, "Foo")


Re: What's the better way to modify rows in a table? by Cor

Cor
Thu Sep 01 02:05:02 CDT 2005

Water Cooler,

>
> (1) An Insert SQLCommand object? or;
> (2) Through the DataRows collection doing it manually and then calling
> Update on the Adapter?

If you only have new unique indentified rows, than the first is in my
opinion the best solution.

I hope this helps,

Cor