[.NET1.1] datarow and itemarray


G

Guest

hi,

I have an issue with datarow and itemarray.
In a datatable I have followong datas :
OPS 014E
OPS <NULL>

I perform a foreach on each datarow like this :
foreach(DataRow dr in aTable.Rows)
{
object[] o = dr.ItemArray
string s1 =
(o[0] != DBNull.Value) ? Convert.ToString(o[0]) : string.Empty;
string s2 =
(o[1] != DBNull.Value) ? Convert.ToString(o[1]) : string.Empty;

}

During my second loop, the value for s2 is 014E and not null
It's strange.

Do you have an idea to solve my problem ?

thanks for your help

best regards

Freddyboy
 
Ad

Advertisements

G

Guest

Hi,
I think your code should work fine.Because below sample code is working
perfect in my VS IDE.A cleaner way to code would be to use foreach for
looping through dr.ItemArray.Below code is working:
DataTable dt = new DataTable();
DataColumn col1 = new DataColumn();
DataColumn col2 = new DataColumn();
col1.DataType = typeof(System.String);
col1.ColumnName ="First";
col2.DataType = typeof(System.String);
col2.ColumnName ="Second";
dt.Columns.Add(col1);
dt.Columns.Add(col2);

DataRow dr1 = dt.NewRow();
DataRow dr2 = dt.NewRow();
dr1["First"] = "manish";
dr1["Second"] = "10";
dt.Rows.Add(dr1);
dr2["First"] = "sanjay";
dr2["Second"] = "";
dt.Rows.Add(dr2);
dt.AcceptChanges();
foreach(DataRow dr in dt.Rows)
{
object[] o = dr.ItemArray;
string s1 = (o[0] != DBNull.Value) ? Convert.ToString(o[0]) :
string.Empty;
string s2 = (o[1] != DBNull.Value) ? Convert.ToString(o[1]) :
string.Empty;
MessageBox.Show(s1);
MessageBox.Show(s2);

}
dataGrid1.DataSource = dt;
 

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

Similar Threads

Slow loading DataRow ItemArray 2
ReadXML retrieving ItemArray 1
accessing the ItemArray[] for a row in a dataset 1
DataRow 2
DataRow? 3
DataRow 1
Editing a Datarow 0
Updating a datarow 2

Top