View Light

HOWTO: Create a new row from a webservice proxy class

Quite a few times, I've needed to create a new row in a table obtained from a web service.

However, just doing a 'new WebService.SomeType.DataModel.SomeTypeRow()' would fail because it doesn't have a public constructor. I was really puzzled and would resort to a hack method of just retreiving an existing row, clearing out all the data, and using it as my new row object. Terrible approach, but I didn't know a better way.

Finally found it - it was there all along, but hadn't noticed it.

Say you've got a DataTable called dtSomeTable obtained from a web service that contains data in the format of SomeTableRow and needed to add a row to the in-memory copy of the data. Just use the (Yes, I was blind to this before) method dtSomeTable.NewRow() to obtain a new copy of it.

I simplified that a bit, you have to cast the NewRow to the proper row type (SomeTableRow in this example) before it works.

Here's a rough example:

Middleware.WebService.SomeType.DataModel.SomeTable someTable = bllSomething.GetAll();

Middleware.WebService.SomeType.DataModel.SomeTableRow rowNew = someTable.NewRow() as Middleware.WebService.SomeType.DataModel.SomeTableRow;

There you go, you now have a new row to add to the table. Just populate it with data, then add it to the table as:


Much easier than my original hacky solution!

This site contains copyrighted material the use of which has not always been specifically authorized by the copyright owner. We are making such material available in our efforts to advance understanding of environmental, political, human rights, economic, democracy, scientific, and social justice issues, etc. We believe this constitutes a 'fair use' of any such copyrighted material as provided for in section 107 of the US Copyright Law. In accordance with Title 17 U.S.C. Section 107, the material on this site is distributed without profit to those who have expressed a prior interest in receiving the included information for research and educational purposes. For more information go to: . If you wish to use copyrighted material from this site for purposes of your own that go beyond 'fair use', you must obtain permission from the copyright owner.