DataRow Item property missing

  • Thread starter Marc van den Bogaard
  • Start date
M

Marc van den Bogaard

hello together,

my datarow.item property is missing, i just can accesss the ItemArray
property,
what is wrong with this?

System.Data.DataSet dataset1 = new System.Data.DataSet();

System.Data.DataTable datatable1 = new System.Data.DataTable("table1");

System.Data.DataColumn c1 = new System.Data.DataColumn("index");

System.Data.DataColumn c2 = new System.Data.DataColumn("name");

System.Data.DataColumn c3 = new System.Data.DataColumn("vorname");


dataset1.Tables.Add("table1");

dataset1.Tables["table1"].Columns.Add(c1);

dataset1.Tables["table1"].Columns.Add(c2);

dataset1.Tables["table1"].Columns.Add(c3);


DataRow row1 = dataset1.Tables["table1"].NewRow();

row1.ItemArray[0] = "1";

row1.ItemArray[1] = "peters";

row1.ItemArray[2] = "mark";


//row.Item[0] = "hhh"; <- this doesnt work

dataset1.Tables["table1"].Rows.Add(row1);


string s =
(string)dataset1.Tables["table1"].Rows[0].ItemArray[0].ToString();

MessageBox.Show(s);
 
M

Marc van den Bogaard

ok, this was a misstyping from my side.
but the property is still missing, also with the correct variable name

Marina said:
You have 'row.Item' instead of 'row1.Item'. The datarow variable is 'row1'.

Marc van den Bogaard said:
hello together,

my datarow.item property is missing, i just can accesss the ItemArray
property,
what is wrong with this?

System.Data.DataSet dataset1 = new System.Data.DataSet();

System.Data.DataTable datatable1 = new System.Data.DataTable("table1");

System.Data.DataColumn c1 = new System.Data.DataColumn("index");

System.Data.DataColumn c2 = new System.Data.DataColumn("name");

System.Data.DataColumn c3 = new System.Data.DataColumn("vorname");


dataset1.Tables.Add("table1");

dataset1.Tables["table1"].Columns.Add(c1);

dataset1.Tables["table1"].Columns.Add(c2);

dataset1.Tables["table1"].Columns.Add(c3);


DataRow row1 = dataset1.Tables["table1"].NewRow();

row1.ItemArray[0] = "1";

row1.ItemArray[1] = "peters";

row1.ItemArray[2] = "mark";


//row.Item[0] = "hhh"; <- this doesnt work

dataset1.Tables["table1"].Rows.Add(row1);


string s =
(string)dataset1.Tables["table1"].Rows[0].ItemArray[0].ToString();

MessageBox.Show(s);

-------------------------------------------------

its just a silly example so dont blame me for this ;)

thank you in advance!
 
M

Marina

Ok, the issue is that in C#, this is the indexer for the class. It's not an
actual property.

It's a property in VB, because VB mixes up the concept of properties and
indexers, and an indexer in VB is declared as a 'default property'.

So to use it in C#, you would say:

row1[0] = "blah";

Marc van den Bogaard said:
ok, this was a misstyping from my side.
but the property is still missing, also with the correct variable name

Marina said:
You have 'row.Item' instead of 'row1.Item'. The datarow variable is 'row1'.

Marc van den Bogaard said:
hello together,

my datarow.item property is missing, i just can accesss the ItemArray
property,
what is wrong with this?

System.Data.DataSet dataset1 = new System.Data.DataSet();

System.Data.DataTable datatable1 = new System.Data.DataTable("table1");

System.Data.DataColumn c1 = new System.Data.DataColumn("index");

System.Data.DataColumn c2 = new System.Data.DataColumn("name");

System.Data.DataColumn c3 = new System.Data.DataColumn("vorname");


dataset1.Tables.Add("table1");

dataset1.Tables["table1"].Columns.Add(c1);

dataset1.Tables["table1"].Columns.Add(c2);

dataset1.Tables["table1"].Columns.Add(c3);


DataRow row1 = dataset1.Tables["table1"].NewRow();

row1.ItemArray[0] = "1";

row1.ItemArray[1] = "peters";

row1.ItemArray[2] = "mark";


//row.Item[0] = "hhh"; <- this doesnt work

dataset1.Tables["table1"].Rows.Add(row1);


string s =
(string)dataset1.Tables["table1"].Rows[0].ItemArray[0].ToString();

MessageBox.Show(s);

-------------------------------------------------

its just a silly example so dont blame me for this ;)

thank you in advance!
 
S

Shiva

Item is the indexer property for DataRow. Access it like an array as in
row1[0] = "hhh";

hello together,

my datarow.item property is missing, i just can accesss the ItemArray
property,
what is wrong with this?

System.Data.DataSet dataset1 = new System.Data.DataSet();

System.Data.DataTable datatable1 = new System.Data.DataTable("table1");

System.Data.DataColumn c1 = new System.Data.DataColumn("index");

System.Data.DataColumn c2 = new System.Data.DataColumn("name");

System.Data.DataColumn c3 = new System.Data.DataColumn("vorname");


dataset1.Tables.Add("table1");

dataset1.Tables["table1"].Columns.Add(c1);

dataset1.Tables["table1"].Columns.Add(c2);

dataset1.Tables["table1"].Columns.Add(c3);


DataRow row1 = dataset1.Tables["table1"].NewRow();

row1.ItemArray[0] = "1";

row1.ItemArray[1] = "peters";

row1.ItemArray[2] = "mark";


//row.Item[0] = "hhh"; <- this doesnt work

dataset1.Tables["table1"].Rows.Add(row1);


string s =
(string)dataset1.Tables["table1"].Rows[0].ItemArray[0].ToString();

MessageBox.Show(s);
 

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