Creating a new row into a datatable

A

Alcibiade

Hi guys,I'm becoming mad with this issue.
I'd like to create some rows and add them to a datatable, but I am not
able.
The code I'm using is this:

DataTableCapitalDetailDataTable Detailtable = new
CapitalDetailDataSet.DataTableCapitalDetailDataTable();
DataTableCapitalDetailRow[] rows = new
CapitalDetailDataSet.DataTableCapitalDetailRow[1];
Array.Resize(ref rows, m_years - 1);
int current_year=DateTime.Now.Year ;
foreach
(wcespiti.DataLayer.CapitalDetailDataSet.DataTableCapitalDetailRow
singlerow in rows)
{

singlerow.title="";//<-i get error......singlerow is
null :S
singlerow.capital_year=(short)current_year++;
singlerow.capital_month= (short )DateTime.Now.Month;
singlerow.period_id=0;//da cambiare
Detailtable.Rows.Add(singlerow);
}

Any suggestion? Thanks
 
A

Arne Vajhøj

Hi guys,I'm becoming mad with this issue.
I'd like to create some rows and add them to a datatable, but I am not
able.
The code I'm using is this:

DataTableCapitalDetailDataTable Detailtable = new
CapitalDetailDataSet.DataTableCapitalDetailDataTable();
DataTableCapitalDetailRow[] rows = new
CapitalDetailDataSet.DataTableCapitalDetailRow[1];

Insert:

rows[0] = new DataTableCapitalDetailRow();
Array.Resize(ref rows, m_years - 1);
int current_year=DateTime.Now.Year ;
foreach
(wcespiti.DataLayer.CapitalDetailDataSet.DataTableCapitalDetailRow
singlerow in rows)
{

singlerow.title="";//<-i get error......singlerow is
null :S
singlerow.capital_year=(short)current_year++;
singlerow.capital_month= (short )DateTime.Now.Month;
singlerow.period_id=0;//da cambiare
Detailtable.Rows.Add(singlerow);
}

Any suggestion?

See above.

Arne
 
A

Alcibiade

What error?

No overload for DataTableCapitalDetailRow() takes 0 parameter.
Beyond this why should I initialize only the number 0 index?? I think
I should introduce this instructions for every field of array:

wcespiti.DataLayer.CapitalDetailDataSet.DataTableCapitalDetailRow[]
rows = new
wcespiti.DataLayer.CapitalDetailDataSet.DataTableCapitalDetailRow[5];
Array.Resize(ref rows, m_years - 1);
rows[0] = new
wcespiti.DataLayer.CapitalDetailDataSet.DataTableCapitalDetailRow(); //
<- error
int index=0;

foreach (DataTableCapitalDetailRow singlerow in rows)
{
rows[index++]=new DataTableCapitalDetailRow() ;
......
 
J

Jeff Johnson

No overload for DataTableCapitalDetailRow() takes 0 parameter.

So let Intellisense tell you what parameters the constructor takes. I can't
tell you off the top of my head what it might look like because I don't use
strongly-typed datasets.
 
A

Arne Vajhøj

What error?

No overload for DataTableCapitalDetailRow() takes 0 parameter.
Beyond this why should I initialize only the number 0 index?? I think
I should introduce this instructions for every field of array:

wcespiti.DataLayer.CapitalDetailDataSet.DataTableCapitalDetailRow[]
rows = new
wcespiti.DataLayer.CapitalDetailDataSet.DataTableCapitalDetailRow[5];
Array.Resize(ref rows, m_years - 1);
rows[0] = new
wcespiti.DataLayer.CapitalDetailDataSet.DataTableCapitalDetailRow(); //
<- error
int index=0;

foreach (DataTableCapitalDetailRow singlerow in rows)
{
rows[index++]=new DataTableCapitalDetailRow() ;
.....

The error message say it all.

The class DataTableCapitalDetailRow does not have a no arg
constructor.

It is not a .NET framework class - it is your class, so you should
know what arguments you need for constructor.

Arne
 
J

Jeff Johnson

It is not a .NET framework class - it is your class, so you should
know what arguments you need for constructor.

My guess is that it's "sort of" his class; it was probably generated by
Visual Studio. But the code is there--somewhere--and the OP ought to be able
to determine what constructor(s) the class has one way or another.
 
Top