|
Thanks! I'll use one of these convertors.
|
|
|
|
|
In your example you have a button2 that does a quick search of the datagridview contents using the string "Stephen" if I remember correctly.
I tried to duplicate your search example in my project using the text contents of a textbox instead.
However the variable "index" is not updated correctly. Instead, I get the result one would expect from a string not found. index ends up at "-1" even if the string exists in the data source, or in the typedlist.
The only thing I have changed is a single line of code from your example.
Rather than using an actual string in the blist.find, I use a textbox2.text, otherwise it's identical.
int index = bList.Find(tList.GetItemProperties(null)[0], textBox2.Text);
Any idea what's going on here anyone?
BTW, Sebastien, I got my other problem working. I chose the simple method.
Thanks for all your help.
Rich
|
|
|
|
|
- You have to pick the right column in tList.GetItemProperties(null)[0] -> [0] = column 0, [1] = column 1, ...
- The demo code is looking for an exact search, it's not a substring
|
|
|
|
|
So my options are to search all the columns sequentially, 0-index max, or provide a drop down box to pick the column to search, and hence it's index.
Alright, thanks again.
Rich.
|
|
|
|
|
Original problem misunderstood, this is a repost with a clarified description, of what I've found out.
Problem, my header is on a line that starts with
#fields:
hence it's commented out, how do I fix this without editing the files?
Rich
modified on Tuesday, October 28, 2008 5:56 PM
|
|
|
|
|
I ran a quick test just to make sure and I do not see that behavior. Are you using the latest version ?
const string Data = "#comment1\n#comment2\n#comment3\ncol1,col2,col3\n1,2,3\n4,5,6";
using (CsvReader csv = new CsvReader(new System.IO.StringReader(Data), true))
{
while (csv.ReadNextRecord())
{
for (int i = 0; i < csv.FieldCount; i++)
Console.Write(csv[i]);
}
}
|
|
|
|
|
Change the comment char. Look at the various constructor overloads for where you can change it. Please, do spend a bit of time thinking before posting questions.
|
|
|
|
|
Sorry I made you post two answers, I tried to edit it quickly, before you saw it. Since I was working fast,I wasn't clear enough with my description.
The problem is, I have 5 lines that are commented out, all with #. 4 of them before the #fields: line.
The files are generated from another program.
If I just change the comment char, it will not fix it, because of the 4 lines ahead of that. I'll have an invalid header, and the same problem.
I think that rather than changing it, I need to change the way headers are built, in my case. For example, have it look for the line that starts with #Fields: to build the header from.
There are two different types of logs with different numbers of columns.
I guess my other option would be to edit the file before I open it. just place a return between #fields, and the next word, However, this will invalidate the log file, and cause a new one to be created to replace it, by the program that made the first one. Hence, I think modifying the header build code slightly to do a string compare and start there would be cleaner.
Sorry for the confusion, can you point me to that code? If not that's cool, I'll find it eventually.
Rich
|
|
|
|
|
Why make something simple when it can be made otherwise
|
|
|
|
|
<br />
private void button1_Click(object sender, EventArgs e)<br />
{<br />
OpenFileDialog dia = new OpenFileDialog();<br />
DialogResult res = dia.ShowDialog();<br />
(res == DialogResult.OK)<br />
{<br />
textBox1.Text = dia.FileName;<br />
<br />
using (CachedCsvReader csv = new CachedCsvReader(new StringReader(textBox1.Text), true))<br />
{<br />
dataGrid1.DataSource = csv;<br />
<br />
}<br />
MessageBox.Show("Your Data source is now " + textBox1.Text);<br />
}<br />
}
I see it done similarly in another example where you simply open a file called "data.csv"
All my code does in spite of the fact that it's just text, like data.csv, is show the text string of the path + filename in the grid view.
What should I be doing here?
|
|
|
|
|
Replace StringReader by StreamReader and you should be good to go. Right now, you are parsing the content of the textbox instead of the file
|
|
|
|
|
Thanks, I knew it was something silly.
|
|
|
|
|
I downloaded the source and when I open LumenWorks.Framework.IO.csproj, C# Express IDE complains "The project type is not supported by this installation" error message" and "The project C:\Temp\CsvReader\CsvReaderDemoWeb\CsvReaderDemoWeb.csproj cannot be opened". I also get the same error message when I try to open that project directly.
Any ideas on how to fix this? I'm using Visual C# Express 2008 on XP SP2.
|
|
|
|
|
Hum, I guess web projects are not supported by the Express edition ... What you can do is create another solution and load all projects, except the CsvReaderDemoWeb. That project is not necessary to compile the library, it is merely a demo project.
|
|
|
|
|
You're right, evidently C# Express doesn't support web projects. I did get your existing CsvReader.sln to build after I installed NUnit tester and assigned a path to to the newly installed NUnit.framework under the project properties Reference Path settings.
Kudos for CsvReader! It works great after I configured it be more forgiving by setting csv.MissingFieldAction to MissingFieldAction.ReplaceByEmpty.
|
|
|
|
|
Maybe I am missing something, but i just can't seem to figure out the problem with the last missing field. I've looked at the other messages related to this, but they don't seem to solve my issue.
Here's the sample of data (comma seperator, quote text qualifier, double quote escape, and MissingFieldAction.ParseError). 5 fields in each row, and record two has missing last field.
This sample does not throw error, but yet it is missing last seperator so last field is missing. Shouldn't this throw an error?
"Part Number","Part Description","Price","Weight","Information"
"0050010790","3/4"" LUG BOLT","3.73","",""
"0010095200","CYLINDER FRAME","588.75",""
"0010095224","CYLINDER GATE","726.06","",""
This sample thows an error, but at field 4, not field 5 even though it is only missing the last seperator. Why is there an error at field 4 if there is a seperator for it?
"Part Number","Part Description","Price","Weight","Information"
"0050010790","3/4"" LUG BOLT","3.73","",""
"0010095200","CYLINDER FRAME","588.75",
"0010095224","CYLINDER GATE","726.06","",""
Please help. Thanks.
|
|
|
|
|
While parsing the 4th field, the expected token is [delimiter], which is absent. The parser does not know if the field value is complete or not. In the example:
foo,bar,baz,Sébasti
"en" is missing at the end of my name in the 4th field. The reader cannot determine if the value is complete or not and so, it is pessimistic about it.
If you want to get the partial value and still know which fields are missing, use the MissingFieldAction.ReturnNullValue option instead. Missing fields will have a null value instead of String.Empty.
|
|
|
|
|
Yes, i see what you mean in your example, but if there are text qualifiers enclosing "Sébasti",
foo,bar,baz,"Sébasti"
it does not set the missing field to null. The missing field is has a value of string.empty.
|
|
|
|
|
I tried using a different text qualifier and escape character, but it exhibits the same behavior. As long as the last field is enclosed in the text qualifier, the missing field will have a String.Empty value.
Thanks for your help. Great proj by the way.
|
|
|
|
|
Well, the conditions are narrower than that. The behavior you see happens only for the last record before EOF and only if the last present field is quoted. I will look into that to correct that edge case. Thanks for reporting the bug
|
|
|
|
|
FYI ... I'm using VB.Net in my testing, it actually occured at any point. I discovered it while adding different test cases to the beginning and middle of my test file. I didn't realize it was a bug, I was hoping it was incorrect construct or properties I was using.
Thanks once again for your proj and help.
|
|
|
|
|
If possible, could you post your sample data, because I was not getting this behaviour in the quick tests I made after I read your previous post. I will be checking this issue more thoroughly later.
|
|
|
|
|
Here's some of the data I was testing with.
"Part Number","Part Description","Price","Weight","Information"
"0010095200-kd","CYLINDER FRAME..","588.75","weight"
"0010095224-kd","CYLINDER GATE CAMECO","726.a06","",""
"0020033326-kd","VALVE RELIEF","70.93","",""
"0020033327-kd"
"0020048048-kd","VALE STEM (20E)","117.07","",""
"0050001440-kd",6.80","",""
"0050009641-kd","BOLT (20e)","4.77",
"0050010035-kd","BOLT","",""
"0050010138-kd","LOCK NUT","2.64","",""
"0050010197-kd","NUT (20E)","1.01","",""
"0050010199-kd","LOCK NUT (20E)","4.05","",""
"","0.46","",""
"0050010204-kd","NUT","0.80","",""
"0050010790-kd","3/4"" LUG BOLT","3.73","",""
"005001218-kd","BUSHING CAMECO","12.06","",""
"0050022596-kd","LOCK NUT","47.43","",""
"0050025505-kd","","0.56","",""
"0050028027-kd","HUB AXLE NUT","7.85","",""
"0050028067-kd","HUB AXLE WASHER","4.77","",""
"CYLINDER BOLT","38.01","",""
"0050033315-kd","AXLE NUT","5.82","",""
"0050298275-kd","YOKE BOLT","65.06","",""
"0051366510-kd","THRUST WASHER","10.19","",""
"0051372113-kd","WASHER","3.17","",""
"B187","HITCH PIN (1.5"" X 17"")","","",""
"B439-9","WEAR PLATE","","",""
"1020837","GREASE FITTING","","",""
"R200-3","PIN","","",""
"037000535","Grease Zerk","0.50","",""
|
|
|
|
|
Hi Sebastien,
Thanks for you CSV Reader, it's been a great help. I've got the latest version.
Unfortunately, the data being read now includes double quotes within the columns, highlighted below.
"",10173,"Development Manager - Social Economy Sector","Trust Bank",10153,,"Lolalll Pudd","Meet the requirements of Structured Finance & Relationship Teams for "transaction support" at all times, ensuring appropriate analysis and clarity in respect of required/request","",09-Sep-2008,42000,38000,"+ LTA + bonus",,,,41000,45000,,,"","",,"","","",,,"",,"A","AUK,AUL,AUN,CBE,RBD"
This is now throwing an error. I've looked at many code examples but can't work out the best way to deal with this.
I'd like to change the Quote value, but this is a read only property.
Do you have some examples of how to change this value, or the escape value.
Thanks in advance.
Trevor
|
|
|
|
|
You can specify quote, escape, delimiter and comment characters in the constructor (look at the overloads). Unfortunately, there is no built-in way to deal with CSV file malformed the way you describe.
|
|
|
|
|