Re: Dataset not Clearing



"tshad" <tfs@xxxxxxxxxxxxxx> wrote in message
news:OXe9LtYbIHA.4712@xxxxxxxxxxxxxxxxxxxxxxx
"Michael Nemtsev [MVP]" <nemtsev@xxxxxxx> wrote in message
news:900895ec2b04a8ca3bd88ac7f170@xxxxxxxxxxxxxxxxxxxxxxx
Hello tshad,

Seems that it's code optimization :)
Try to trace the dataSet content after clearing it in release mode.
Because I assume that in debug it just don't clear it when u ask and keep
it till u either override it or exit the function

That doesn't appear to be the case, because it is getting cleared.

Only the column names are not getting cleared.

I found out how to make it work, I just don't know why I would have to do
this:

If I add ds.tables.clear() after ds.clear(), this will clear the column
names as well.

This doesn't make sense to me as I would have thought that ds.clear (which
gets rid of the tables) would also get rid of the columns names for the
tables which now don't exist.

Thanks,

Tom


If I trace it through, before my da.Fill() I get:
ds.Tables[0].Rows[0][0] 'ds.Tables[0]' threw an exception of type
'System.IndexOutOfRangeException' object {System.IndexOutOfRangeException}

This is the same on both passes (which is expected).

For column names it is the same:
ds.Tables[0].Columns[0].ColumnName 'ds.Tables[0]' threw an exception
of type 'System.IndexOutOfRangeException' string
{System.IndexOutOfRangeException}

But it is only the same on the first pass. On the second pass, the rows
show as out of range, but the column names are the same as I set them on
the first pass.

The problem is that on the first pass, the column names are what is in the
1st column of row 0 of the csv file (which is what I want). But on the
2nd pass, it stays what I changed it to and never picks up the 1st column
of the 2nd file. The problem is that this column tells me what type of
file I am dealing with.

Why doesn't it read the first column here?

My connection string says to use the headers from the 1st row, which it
does on the first file:

OleDbConnection csvConnection = new
OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" +
csvPath + ";Extended Properties=\"Text;HDR=Yes;FMT=Delimited\"");

"HDR=Yes;"

Thanks,

Tom

---
WBR, Michael Nemtsev [.NET/C# MVP] :: blog:
http://spaces.live.com/laflour
"The greatest danger for most of us is not that our aim is too high and
we miss it, but that it is too low and we reach it" (c) Michelangelo

t> I am trying to clear my dataset each time I read a new csv file but
t> it seems to keep the data from the previous time.
t> t> If I do:
t> *********************************************************************
t> ***********
t> foreach (string strFile in strFiles)
t> {
t> ds.Clear();
t> da = new OleDbDataAdapter("SELECT * FROM " +
t> Path.GetFileName(strFile),csvConnection);
t> da.Fill(ds);
t> foreach (DataTable dt in ds.Tables)
t> {
t> for (int i=0;i<dt.Columns.Count-1;i++)
t> {
t> switch(i)
t> {
t> case 0:
t> formName = dt.Columns[i].ColumnName.Replace("Form ","");
t> dt.Columns[i].ColumnName = "FieldName";
t> break;
t> *********************************************************************
t> ************
t> The second time I read a file (after the ds.Clear();) I find that my
t> dt.Columns[i].ColumnName will be equal to "FieldName", which is what
t> I change the column to the first time around!!!
t> t> Why is that?
t> t> It should be what is in the first row, first column of the table,
t> since I wiped out the table. If not, how do I get it to work
t> correctly?
t> t> Thanks,
t> t> Tom
t>





.



Relevant Pages

  • Re: Dataset not Clearing
    ... Try to trace the dataSet content after clearing it in release mode. ... My connection string says to use the headers from the 1st row, ... t> foreach (string strFile in strFiles) ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Dataset not Clearing
    ... Try to trace the dataSet content after clearing it in release mode. ... My connection string says to use the headers from the 1st row, ... t> foreach (string strFile in strFiles) ...
    (microsoft.public.dotnet.framework.aspnet)
  • How to use Log4net TelnetAppender and Trace Listeners
    ... Is there a way to use Log4net and Trace Listeners? ... public static void Initialize(string traceListeners, ... public static void Flush2File(string file, string msg, bool ...
    (microsoft.public.dotnet.framework)
  • Re: [PATCH] tracing/markers: make markers select tracepoints
    ... trace points need translation. ... this hook may break. ... without even needing to reboot the kernel. ... Given that the string is self describing, ...
    (Linux-Kernel)
  • Re: How to look at parameter string
    ... I am tracing, but the problem I can't trace (at least, I haven't figured out ... string it is putting together to send to Sql. ... >> The problem is not coming from Sql Server but from my page. ...
    (microsoft.public.dotnet.framework.adonet)