datatable.newrow HOW THE HELL

  • Thread starter Al Bastido via .NET 247
  • Start date
A

Al Bastido via .NET 247

could somebody please explain to me how the datatable.newrow method works, i've been trying to figure it out for weeks. I need to emulate it myself.

I can bind my datagrid to a collection of objects with no problem. But that leaves me with a fixed number of properties per object and therefore a fixed number of columns in my datagrid.

I wanted to do something similar to the datatable, where you add columns then have a method that generates a row object based on the column schema.

The reason i want to do this is to be able to hold objects in the table rather than scalar value as the datatable does.

Thanks in advance - i'm getting to the stage of dispear
)
 
S

scorpion53061

Dim dro as DataRow = someDataTable.NewRow
DataRow dro = someDataTable.NewRow();

'add the values respectively for each field

finally,
someDataTable.Rows.Add(dro);
//same for c# in this case.

Then just call DataAdapter.Update

There's a bunch that coudl be going wrong. How have you tried to add
the
rows? Are you getting any exceptions? (Make sure you don't have any
try/catch blocks that don't do anything but eat the exception

Also verify that you DataSet.hasChanges

Cheers,

Bill Ryan
 
W

William Ryan eMVP

It'd help if you posted what you were currently doing, but this is
essentially the snytax:

C#
DataRow dro = DataTableName.NewRow();
dro[0] = "whatever";
dro[1] = "you get the idea";
DataTableName.Rows.Add(dro);

VB.NET
Dim dro as DataRow = new DataRow
dro(0) = "whatever"
dro(1) = "you get the idea"
DataTableName.Rows.Add(dro)
--

With that said, I'm not sure how it relates to your problem. If you bind to
a datatable or a collection, you can add new values to it. If you
implemented a strongly typed collection then it would be quite easy, just
define a new instance of the object. As far as the columns go, I don't see
how it's any different other than not being as clean as a datatable. In
most instances, you can model quite a few things using a datatable directly.
If you look at what most ORM tools like Deklarit and LLBLGen do, the
effectively make the bridge between your object(s) and the dataTables(s),
which you can certainly do on your own although using one of those two tools
makes it a dream. You can get a good idea of how a datatable is implemented
by looking at its structure in the documentation. I may have misunderstood
your question though and If I did, please let me konw and I'll see what I
can do.

Cheers,

Bill

W.G. Ryan, eMVP

http://forums.devbuzz.com/
http://www.knowdotnet.com/williamryan.html
http://www.msmvps.com/WilliamRyan/
Al Bastido via .NET 247 said:
could somebody please explain to me how the datatable.newrow method works,
i've been trying to figure it out for weeks. I need to emulate it myself.
I can bind my datagrid to a collection of objects with no problem. But
that leaves me with a fixed number of properties per object and therefore a
fixed number of columns in my datagrid.
I wanted to do something similar to the datatable, where you add columns
then have a method that generates a row object based on the column schema.
The reason i want to do this is to be able to hold objects in the table
rather than scalar value as the datatable does.
 
C

Cowboy \(Gregory A. Beamer\) [MVP]

New row simply creates a new row with a specific set of columns. You still
have to fill it and bind it back to the DataTable. I have a sample
somewhere. I will see if I can dig it up.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

************************************************
Think Outside the Box!
************************************************
Al Bastido via .NET 247 said:
could somebody please explain to me how the datatable.newrow method works,
i've been trying to figure it out for weeks. I need to emulate it myself.
I can bind my datagrid to a collection of objects with no problem. But
that leaves me with a fixed number of properties per object and therefore a
fixed number of columns in my datagrid.
I wanted to do something similar to the datatable, where you add columns
then have a method that generates a row object based on the column schema.
The reason i want to do this is to be able to hold objects in the table
rather than scalar value as the datatable does.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top