Re: Dataset not Clearing
- From: "tshad" <tfs@xxxxxxxxxxxxxx>
- Date: Tue, 12 Feb 2008 07:24:03 -0800
"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.
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>
.
- Follow-Ups:
- Re: Dataset not Clearing
- From: tshad
- Re: Dataset not Clearing
- References:
- Dataset not Clearing
- From: tshad
- Re: Dataset not Clearing
- From: Michael Nemtsev [MVP]
- Dataset not Clearing
- Prev by Date: Upload File
- Next by Date: Re: Dataset not Clearing
- Previous by thread: Re: Dataset not Clearing
- Next by thread: Re: Dataset not Clearing
- Index(es):
Relevant Pages
|