Re: Update DataTable (from csv import) data

Tech-Archive recommends: Fix windows errors by optimizing your registry



I am getting the following error: 'dr' is a 'variable' but is used like a
'method'.
Am I missing something? I know I can't use the Equals method because I need
to identify the column. How do I select the column to compare?

--
Regards,

Mike D


"AMDRIT" wrote:

I guess my first question is how did you import the CSV file? I assumed you
used some sort of reader and were creating the datarows as you read each
line, that would be the best place to put your date correction code.

In any event, and assuming that your date field in the datatable is defined
as a string and not as a date.

//assuming you have a datatable object named objTable
foreach datarow dr in objTable.rows
{
if (dr("datefieldname")=="00/00/0000")
{
dr.setNull("datefieldname")
//or
dr("dateFieldName") = date.minvalue // "12:00 AM" --FYI
}
}

if the datefield is a date, then "00/00/0000" should have caused an
exception along the way because it is an invalid date, or the value should
already == date.minvalue or isdbnull(dr("datefieldname"))


"Mike D" <MikeD@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:EF67840C-535D-4719-84D0-FF50D5EC004E@xxxxxxxxxxxxxxxx
First - Thanks for the reply. Second - How would I loop through the
DataTable to find the rows with the invalid dates? Would I use foreach or
a
for loop (if so how would I implement it on a DataTable - row.count)?
BTW - I am new to C# and .NET so pardon nood questions. I used to be a
ColdFusion developer for 7 years.
--
Regards,

Mike D


"AMDRIT" wrote:

You will have to allow the date field to allow null values or set the
date
to some constant arbitrary value (i.e. date.minvalue). When setting the
dates in the datatable to null all you need to do is either not set the
value or datarow.setnull("datefieldname") if you are going to allow nulls
or
set the value to some arbitrary value datarow("datefieldname") =
date.minvalue. Your data adapter will know what to do if you accomodate
as
I have suggested.




"Mike D" <MikeD@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:12719B89-307C-4FC7-8330-AF77BDF0231D@xxxxxxxxxxxxxxxx
I have finally been able to import a csv file into a DataTable. The
data
has
invalid dates which won't insert into the SQL table I have. So I have
been
trying to figure out how to DBNull the invalid dates while still in the
DataTable but I don't understand C# (or .NET) enough to know what or
how
to
do it. There are two date fields which have '00/00/0000' and may have
'fat-fingered' dates too, so I basically need to loop over the
DataTable
row-by-row and perform a check of the data in the two fields (I have an
isDate(object obj) method). If the data is invalid then DBNull the
value.
So far I have created a SqlDataAdpater and a DataTable and now I hit
the
brick wall as to what to do next. The DataTable has 19 columns and is
usually over 30,000 rows. Any ideas, help, or guidance?
--
Regards,

Mike D






.



Relevant Pages

  • Re: CNET.com
    ... >> the DNS and getting an invalid address, ... --- "Mike" wrote in message ... If not you won't have nslookup and>> will have to check that your HOSTS file isn't causing any>> interference in the lookups. ...
    (microsoft.public.windows.inetexplorer.ie6.browser)
  • Re: Republic of Mike Terry
    ... We aren't all able to spend our days browsing the Internet for articles that might interest us. ... Also, cut and pasting large or complete chunks of text, with or without an accompanying attributed URL might breach copyright. ... Mike fills many Usenet groups with unnecessary baggage such as this, though thankfully most of it is On Topic. ... Please replace invalid and invalid with gmx and net to reply. ...
    (alt.radio.digital)
  • Re: Update DataTable (from csv import) data
    ... foreach datarow dr in dtTmpTable.rows ... Mike D ... DataTable to find the rows with the invalid dates? ... for loop? ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: "Fair (hah) and Balanced (giggle)"
    ... rape, for reasons we've at least touched on). ... initiate lethal force in self defense - aggressive drooling will be ... data and you and Mike don't, you know that his data ... hereafter that anything the previous poster said was invalid. ...
    (rec.arts.sf.fandom)
  • Re: Update DataTable (from csv import) data
    ... AMDRIT wrote: ... invalid dates which won't insert into the SQL table I have. ... If the data is invalid then DBNull the value. ... Actually Date.MinValue is not a value that SQL Server will accept ... ...
    (microsoft.public.dotnet.framework.adonet)