DataTable Edits

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

How do I edit or reformat a DataTable?
DataTable orders;
getSqlData(orders);
for (int i;i<orders.row.count;i++)
{
orders.row.ItemArray[0] = "Some special edits";
}
orders.AcceptChanges();

The code above doesn't do anything!
How can I update my ItemArray?
 
Arne Garvander said:
How do I edit or reformat a DataTable?
DataTable orders;
getSqlData(orders);
for (int i;i<orders.row.count;i++)
{
orders.row.ItemArray[0] = "Some special edits";
}
orders.AcceptChanges();


DataTable orders;
getSqlData(orders);
for (int i;i<orders.row.count;i++)
{
orders.row.[ColumnIndex] = "Some special edits";
}
orders.AcceptChanges();
--If I understand you correctly, this should do it.
 
orders.Rows.[0]= 1 ; doesn't compile

--
Arne Garvander
(I program VB.Net for fun and C# to get paid.)


W.G. Ryan - MVP said:
Arne Garvander said:
How do I edit or reformat a DataTable?
DataTable orders;
getSqlData(orders);
for (int i;i<orders.row.count;i++)
{
orders.row.ItemArray[0] = "Some special edits";
}
orders.AcceptChanges();


DataTable orders;
getSqlData(orders);
for (int i;i<orders.row.count;i++)
{
orders.row.[ColumnIndex] = "Some special edits";
}
orders.AcceptChanges();
--If I understand you correctly, this should do it.
 
He had a a typo. Obviously the '.' in between and [0] has to go.

Arne Garvander said:
orders.Rows.[0]= 1 ; doesn't compile

--
Arne Garvander
(I program VB.Net for fun and C# to get paid.)


W.G. Ryan - MVP said:
message
How do I edit or reformat a DataTable?
DataTable orders;
getSqlData(orders);
for (int i;i<orders.row.count;i++)
{
orders.row.ItemArray[0] = "Some special edits";
}
orders.AcceptChanges();


DataTable orders;
getSqlData(orders);
for (int i;i<orders.row.count;i++)
{
orders.row.[ColumnIndex] = "Some special edits";
}
orders.AcceptChanges();
--If I understand you correctly, this should do it.
 
Thanks Marina - yep, I edited it in Outlook's window and left in the '.'
Marina Levit said:
He had a a typo. Obviously the '.' in between and [0] has to go.

Arne Garvander said:
orders.Rows.[0]= 1 ; doesn't compile

--
Arne Garvander
(I program VB.Net for fun and C# to get paid.)


W.G. Ryan - MVP said:
message
How do I edit or reformat a DataTable?
DataTable orders;
getSqlData(orders);
for (int i;i<orders.row.count;i++)
{
orders.row.ItemArray[0] = "Some special edits";
}
orders.AcceptChanges();

DataTable orders;
getSqlData(orders);
for (int i;i<orders.row.count;i++)
{
orders.row.[ColumnIndex] = "Some special edits";
}
orders.AcceptChanges();
--If I understand you correctly, this should do it.

 
I am having a problem updating the data in my DataTable (30,000+ rows) prior
to inserting it into a SQL table. The DataTable is filled (from a csv file
which output by SAP) by a DataAdapter. Two of the columns in the DataTable
have invalid dates (00/00/0000) which need to be changed to NULL. I adapted
the code you suggested above to the following:

DataRow[] drCreateDate;
drCreateDate = dtTmpTable.Select("[Create Date] = '00/00/0000'");
for (int i = 0; i < drCreateDate.Length; i++)
{
dtTmpTable.Rows[14] = DBNull.Value;
}
DataRow[] drCloseDate;
drCloseDate = dtTmpTable.Select("[Close Date] = '00/00/0000'");
for (int i = 0; i < drCloseDate.Length; i++)
{
dtTmpTable.Rows[15] = DBNull.Value;
}
dtTmpTable.AcceptChanges();

However it doesn't update ALL the invalid dates. It seems to get only the
invalid ones up to the first valid date. What am I missing or doing wrong?
 
Back
Top