"randy" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hello all,
>
> I have a DataTable which I am building column by column and adding rows
> after each new column. The DataTable columns match the columns in my
> database table. I'm building the DataTable first and I then want to roll
> through the DataTable while in memory checking for errors and then commit
> the rows to my database table (btw this is in ASP.NET). Is it possible to
> have data in a datable before attaching at DataAdapter?
Yes, and you never technically attach a datatable to an adapter. An adapter
could care less what you send to it, it only cares in that it matches the
commands that you try to have it send the db.
I'm a little new to
> this and know I need a SqlCommandBuilder,
Not so, and in all likelihood, avoid the command builder. Check out Bill
Vaughn's article Weaning Developer's from the commandBUilder at
www.betav.com ->Articles ->MSDN
so some code example would be very
> helpful. Below is what I know about using the DataAdapter/CommandBuilder,
> but I don't need to SELECT anything because the DataTable already had new
> rows (that why I put Id = 0 to get no data).
If you use the command builder, you should be ok, but that query will
probably cause drama. The commanduilder infers update/insert/delete logic
based on athe Select Command so that's all it needs. You don't need to
write over your exisitn gdata. You also probably want to use Parameterized
queries... Where ID = @SomeValue"
then do mySelectCommand.Parameters.Add("@SomeValue", SqlDbType.Whatever,
someLength).Value = 0
Run through the dataadapter configuration wizard at least once and check out
the code it generates for you. It will have parameters and column mappings
as well. While I don't recommend using it too much b/c it becomes a crutch,
it's a superb learning too.
Also, you don't have to call Select First. You don't even have to call
update on a datatable that you called fill on, or even one whose data came
from the db. The adapter doesn't care. I know this may seem like a lot so
you may want to check out Bill's article, play with the wizard, and just get
a valid Update command. Then do what you are now, and just call update on
your datatable. Let me know if you have any problems, I'll do my best to
get you through them.
HTH,
Bill
www.devbuzz.com
www.knowdotnet.com
>
> dim dt as New DataTable
> dim da as DataAdapter
> dim sqlCmdBuild as SqlCommandBuilder
>
> da = New SqlDataAdapter("SELECT * FROM Table WHERE Id = 0", OpenDbConn)
> da..Fill(dt)
>
> sqlCmdBuild = New SqlCommandBuilder(da)
>
> TIA,
>
> -Randy
>
>