Re: what am I doing wrong ?



Hi,

Sorry, but msdn2 was offline when I responded last so the link on Typed
DataSets I posted couldn't be verified. It turns out, now that msdn2 is
working again, that the link really only discusses command-line support and
the XSD generator tool.

Here's a more appropriate article with a section that discusses Typed vs.
UnTyped DataSets:

"DataSets in Visual Studio Overview"
http://msdn2.microsoft.com/en-us/library/8bw9ksd6(VS.80).aspx

Here's an article that discusses the new features of DataSets in VS 2005:

"New DataSet Features in Visual Studio 2005"
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnvs05/html/newdtastvs05.asp

To get started quickly, just add a new file to your project and choose
"DataSet" from the list of file types.

Have fun :)

--
Dave Sexton

"SLIMSHIM" <SLIMSHIM@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:74FA543F-928A-41FF-9C49-2783FD1CE56D@xxxxxxxxxxxxxxxx
THanks once again you're all great!

I tried the code you wrote and I get this error ..
Update unable to find TableMapping['who'] or DataTable 'who'.
why doesn't it know or find the table.
if I view ds id debugging mide it shows the table name as Table.
I know i"m missing something simple . your help would be much appreciated.


"Dave Sexton" wrote:

Hi,

i"m somewhat confused as to why we need to generate all parameters of the
dataset to do an update. Doesn't the dataset already know which column is
which ?

We're not generating parameters on the DataSet, we're generating parameters
for the OleDbCommand object. The DataSet just contains data and isn't
aware
of the database implementation, adapters, commands, connections or anything
else like that. The names of the DataColumns don't have to be the same as
the
corresponding fields in the database.

can you do something like a "INSERT INTO who * VALUES *"

Unfortunately no, because that's not valid SQL.

The adapter doesn't process your SQL statement, the database does. The
adapter's job is to simply read each DataRow from the specified DataTable
(or
all DataTables) and check the RowState to determine which command (e.g.,
InsertCommand, UpdateCommand, DeleteCommand) should be used to update the
row
in the database. New rows are added using the specified InsertCommand,
modified rows are updated using the specified UpdateCommand and deleted
rows
are removed using the specified DeleteCommand.

For each row, the adapter checks the SourceColumn of each parameter on the
command chosen for that row and grabs the values for the parameters from
the
corresponding DataColumns. After the adapter sets the parameters on the
command from the SourceColumns the command is executed. The next row is
then
processed.

That's the basics of how adapters work but they do offer more control and
functionality than I've described here.

If you can retrieve the datarow why can't we just update the datarow?

That's the adapter's job. The DataRow is just in-memory data and has no
relation at all to the actual data source. Of course, if you only have a
single row then you really don't even need an adapter at all. Just set the
parameters and execute the appropriate command yourself:

OleDbCommand comm = new OleDbCommand("INSERT INTO ...", conn);

comm.AddWithValue("pName", row["name"]);
comm.AddWithValue("pAddress", row["address"]);
comm.AddWithValue("pAge", row["age"]);

comm.ExecuteNonQuery();

please excuse my nubiness!!!
I"m so used to working with tables and records...
Can I retrieve the parameters from the database without needing to retype
it
for the select statement ?

Once you have a select statement, as Cor pointed out, you can use an
OleDbCommandBuilder object to create the other commands. Your select
statement must return a unique or primary key field in order for the
command
builder to work (an exception is thrown otherwise according to the article
below).

"Automatically Generating Commands"
http://msdn2.microsoft.com/en-us/library/tf579hcz.aspx

"OleDbCommandBuilder Class"
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemDataOleDbOleDbCommandBuilderClassTopic.asp

If you're using stored procedures and would like to automatically derive
the
parameters there's an easy way to do that as well:

"OleDbCommandBuilder.DeriveParameters Method"
http://msdn2.microsoft.com/en-us/library/system.data.oledb.oledbcommandbuilder.deriveparameters.aspx

--
Dave Sexton





.



Relevant Pages

  • Re: Problem with Update Adapter
    ... > adapter works is it iterates the Rows collection, ... and then fires the command accordingly. ... >> for a simple data set. ... >> This is just a barebones test using the Northwind database. ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: Problem with Update Adapter
    ... you're using a BindingManager --- manually set a row/column value and see if ... >> adapter works is it iterates the Rows collection, ... and then fires the command accordingly. ... >>> This is just a barebones test using the Northwind database. ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: Microsoft: Making a simple process impossible to use in .NET 2.0
    ... adapter, you need the executescalar for that. ... What you want is a command on its own. ... The connection you can get very easy by getting that from whatever ... able to get a count of items contained in a SQL table by creating a ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: DataTable before DataAdapter possible?
    ... command but that command must map to the datatable in order for you to call ... > Dim datCol as DataColumn ... and you never technically attach a datatable to an adapter. ... The adapter doesn't care. ...
    (microsoft.public.dotnet.general)
  • Re: what am I doing wrong ?
    ... corresponding fields in the database. ... The adapter doesn't process your SQL statement, ... all DataTables) and check the RowState to determine which command (e.g., ... command chosen for that row and grabs the values for the parameters from the ...
    (microsoft.public.dotnet.languages.csharp)