A solution to parsing CSV records that contain embedded commas in quotes

I've seen so many people looking to use StringTokenizer or Split to parse a quoted CSV file, only to fail to handle embedded ','s in quoted fields. So i'm throwing in my 2-cents with my solution that anyone can use freely.
It's small, comes with a little test program and utilizes the String.split function.
Enjoy,
Todd Blackley
[email protected]
www.pawsource.org
Copyright (c) 2005 Todd Blackley
The above copyright notice shall be included in all copies or substantial
portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package com.pawsource.model;
import java.util.*;
public class Csv
public     Csv()
public     void     test1()
     LinkedList     list     = new LinkedList();
     for (int i=0;i<1000000;i++)
     list.add(new String(Integer.toString(i)));
     for (Iterator iter = list.iterator(); iter.hasNext();)
     String     s = (String)iter.next();
     System.out.println(s);
public     String     toCSV(ArrayList aList)
     StringBuffer     buffer     = new StringBuffer();
     for (int i=0;i<aList.size();i++)
     String     text           = (String)aList.get(i);
     boolean     needQuotes     = text.indexOf(",")==-1?false:true;
     if (needQuotes)     buffer.append("\"");
     buffer.append(text);
     if (needQuotes)     buffer.append("\"");
     if (i<aList.size()-1)
          buffer.append(",");
     return buffer.toString();
public     ArrayList     parseCSV(String aBuffer)
     String[]     orig     = aBuffer.split(",");
     ArrayList     tokens     = new ArrayList();
     int     index     = 0;
     while (index<orig.length)
     if (orig[index].startsWith("\""))
          int          origIndex     = index;
          tokens.add(orig[index].substring(1,orig[index].length()));
          while (orig[index].endsWith("\"")==false && ++index<orig.length)
          tokens.set(origIndex,tokens.get(origIndex)+ "," + orig[index]);
          if (index<orig.length)
          String     temp = (String)tokens.get(origIndex);
          tokens.set(origIndex,temp.substring(0,temp.length()-1));
     else
          tokens.add(orig[index]);
     index++;
     return tokens;
public static void main(String[] args)
     Csv     test = new Csv();
     System.out.println("Start...");
     String     buffer     = "1,2,,4,\"5,6,7,8\",9,10";
     ArrayList     tokens = test.parseCSV(buffer);
     for (int i=0;i<tokens.size();i++)
     System.out.println("Token :" + tokens.get(i));
     System.out.println("CVS :" + test.toCSV(tokens));
     System.out.println("Finish...");
}

My $0.2 worth for cleaning up the code (nothing to do with functionality and not trying to be critical):
list.add(new String(Integer.toString(i)));
shoud be
list.add(Integer.toString(i));
no reason to create an extra String since that is what toString() returns
boolean needQuotes = text.indexOf(",")==-1?false:true;
should be
boolean needQuotes = text.indexOf(",")==-1;
and
while (orig[index].endsWith("\"")==false && ++index><orig.length)
should be
while (orig[index].endsWith("\"") && ++index><orig.length)
the rest is redundant
Also, what is "><"?
Both toCSV() and parseCSV should be static because they contain no state.

Similar Messages

  • How do Import a csv file that contains strings

    I have a file that contains numbers as US formmated $$$  such as $1,123,123,123  I have a perl script on one of our linux servers that creates the csv file as
    "Total Dollars","$1,123,123,123","some other string","etc"  but when I import the file into numbers
    Unnamed Table
    Average Price'
    $160
    686'
    $222
    482'
    $114
    820'
    $188
    062'
    I cant find a setting anywhere that says to ignore commas inside a string.  This works in most other applications.

    I apologize but you wrote :
    WALTER-MILANO-ITALY wrote:
    You should be now able to import the file using ; as separator or if you prefer you can do again the change  of ; with ,
    It's not a matter of preferences. The OP can't import a file whose values are separated by semi-colons.
    He must replace them by commas.
    With your scheme :
    Original datas
    'Total Dollars','$1,123,123,123','some other string','etc'
    after your step 1
    'Total Dollars';'$1,123,123,123','some other string','etc'
    after your step 2
    'Total Dollars';'$1,123,123,123''some other string''etc'
    and the datas are completly unusable
    A possible scheme would be :
    Original datas
    'Total Dollars','$1,123,123,123','some other string','etc'
    'Totals Dollars','$12,123,123,123’,’blahblah’,’etc'
    after possible step 1 (replace ‘,’ by ",")
    'Total Dollars";"$1,123,123,123";"some other string";"etc'
    'Totals Dollars";"$12,123,123,123";"blahblah";"etc'
    after possible step 2 (replace single ‘ by ")
    "Total Dollars";"$1,123,123,123";"some other string";"etc"
    "Totals Dollars";"$12,123,123,123";"blahblah";"etc"
    after possible step 3 (replace ";" by ",")
    "Total Dollars","$1,123,123,123","some other string","etc"
    "Totals Dollars","$12,123,123,123","blahblah","etc"
    This one may be imported by Numbers on thez OP’s machine.
    I don't know if these changes may be done with Perl but I know that they are easy to do with AppleScript.
    But honestly, if Perl is able to build a TAB separated values file, it would be more efficient.
    Yvan KOENIG (VALLAURIS, France) mercredi 25 janvier 2012
    iMac 21”5, i7, 2.8 GHz, 12 Gbytes, 1 Tbytes, mac OS X 10.6.8 and 10.7.2
    My Box account  is : http://www.box.com/s/00qnssoyeq2xvc22ra4k

  • SAXParseException when trying to parse a text that contains "&"

    Hi all again,
    now I have another problem parsing text...
    When I try to parse the next xml:
    <?xml version="1.0" encoding="UTF-8"?>
    <areastate><identifier>AREA 01&&&hola</identifier>
    <code>1</code>
    <description>Area unica </description>
    <timestamp>1027058590958</timestamp>
    <activestrategy><identifier>ESTR 101</identifier>
    <description>Estrategia 1 del area 1</description>
    </activestrategy>
    <subarea><identifier>SUBA 101_asdfg</identifier>
    <description>Subarea 1 del area 1</description>
    <operationmode><timetable /></operationmode>
    <subareastreet><streetplan><plan>plan 91</plan>
    <forced><no/></forced>
    <ordered>plan 91</ordered>
    </streetplan><streetcycle><cycle>100</cycle>
    <forced><no/></forced>
    <ordered>100</ordered>
    </streetcycle>
    </subareastreet>
    <subareatimetable><plan>plan 91</plan>
    <cycle>100</cycle>
    </subareatimetable>
    <subareaselection><plan>--</plan>
    <cycle></cycle>
    </subareaselection>
    <subareaadaptative><cycle></cycle>
    </subareaadaptative>
    </subarea>
    </areastate>
    I get this exception :
    org.apache.crimson.parser/P-009
    org.xml.sax.SAXParseException: org.apache.crimson.parser/P-009
         at org.apache.crimson.parser.Parser2.fatal(Parser2.java:3035)
         at org.apache.crimson.parser.Parser2.fatal(Parser2.java:3023)
         at org.apache.crimson.parser.Parser2.maybeReferenceInContent(Parser2.java:2296)
         at org.apache.crimson.parser.Parser2.content(Parser2.java:1754)
         at org.apache.crimson.parser.Parser2.maybeElement(Parser2.java:1468)
         at org.apache.crimson.parser.Parser2.content(Parser2.java:1700)
         at org.apache.crimson.parser.Parser2.maybeElement(Parser2.java:1468)
         at org.apache.crimson.parser.Parser2.parseInternal(Parser2.java:499)
         at org.apache.crimson.parser.Parser2.parse(Parser2.java:304)
         at org.apache.crimson.parser.XMLReaderImpl.parse(XMLReaderImpl.java:433)
         at com.saincotrafico.optimus.client.gui.realtime.XMLListener.creaObjeto(XMLListener.java:109)
         at com.saincotrafico.optimus.client.gui.realtime.XMLListener.onMessage(XMLListener.java:63)
         at org.jboss.mq.SpyMessageConsumer.run(SpyMessageConsumer.java:490)
         at java.lang.Thread.run(Thread.java:484)
    I've noticed that this only happens if one of the values between to tags have an '&'.
    Any ideas? Please it's VERY IMPORTANT as one client of ours has deicided to change identifier of the areas ant put some &&&s in the name. The client, my boss, an more people is hasten on me, and I have now no more ideas.

    You mean that I cannot parse something like
    <id>Daniel&Cia.</id>?
    If that's true I think I'm in a big problem...yes.
    but you can change to use CDATA.
    <![CDATA[<hello> &&&&&&&&&&&&&&&& </hello>]]>
    or change to
    <id>Daniel&#38;Cia.<id>

  • How to handle the records that contain different number of columns

    hi all,
    I have a file (as source data)includes order information like:
    H,P001,Smith,Sunnyvale
    D,P001,PR97623,150,10.99,Ice cream
    D,P001,PR33267,45,32.66,Popcorn
    T,P001
    H,P003,Williams,San Jose
    X,P003,PR23563,19,25.54,Peanuts
    T,P003
    I want to transfer the file record to three target tables,
    the record marked "H" to "Summary" table and sum money of the detail
    the record marked "D" to "Detail" table
    the record marked "X" to "Error" table
    the expect result as below:
    Summary table
    Order_No Customer Address Total_Money
    P001 Smith Sunnyvale 3118.2
    (※3118.2=150*10.99+45*32.66)
    Detail table
    Order_No Prodcut_Id Prodcut_Name Quantity Price
    P001 PR97623 Ice cream 150 10.99
    P001 PR33267 Popcorn 45 32.66
    Error table
    Head Order_No Record_No
    X P003 6
    (※6 is the line no in the file)
    How can I do this in ODI , could anyone give some hints?

    Hi AGUI,
    You can do this by the following way,
    1) create the File datastore for the file with 6 columns
    while creation select the following option file format as Delimited
    record seperator as MS-DOS and field sep as other specify "," in the text box.
    -- check the file datastore maps correctly by view the data.
    2) create the interface int1 for transfer the data from this file to temp table( the temp table should have one more column for getting the line number( it should be the sequence number).
    3) create the another interface int2, in this interafce you need to transfer the data from the[b] temp table to Detail table (use filter for gatting D record.
    4) create the interace int3 transfer the data from the temp table to Summary table. please keep the total_money field as null for this interace
    and use Odi procedure for updating this field with reference of details table.
    5) create interface int4 for transfer the error date by transferinf from temp table to error table.
    Thanks,
    Madha

  • How to suppress records that contain zero values

    Dear folks,
    Please take a look at my query below. This is a sample query with only 6 columns but my actual query has about 70 columns. Basically I need to be able to suppress those rows where numerical values are zeros across a row. But even if one column has a value greater than zero, I need that row. Is there any better way to do it or this is the only way to do it? I am just trying to avoid creating a big WHERE clause with all fields in there. Kind regards.
    with my_table as (
    Select 'A' as org, 12 as val_1, 13 as val_2, 14 as val_3, 40 as val_4, 100 as val_5 from dual
    union all
    Select 'b' as org, 12 as val_1, 13 as val_2, 14 as val_3, 40 as val_4, 100 as val_5 from dual
    union all
    Select 'c' as org, 12 as val_1, 13 as val_2, 14 as val_3, 40 as val_4, 100 as val_5 from dual
    union all
    Select 'A' as org, 0 as val_1, 0 as val_2, 0 as val_3, 0 as val_4, 0 as val_5 from dual)
    select * from my_table
    where
    ( val_1 != 0 And val_2 != 0 and val_3 != 0 and val_4 != 0 and val_5 != 0)

    Hi,
    dreporter wrote:
    Dear folks,
    Please take a look at my query below. This is a sample query with only 6 columns but my actual query has about 70 columns. Basically I need to be able to suppress those rows where numerical values are zeros across a row. But even if one column has a value greater than zero, I need that row. Is there any better way to do it or this is the only way to do it? I am just trying to avoid creating a big WHERE clause with all fields in there. Kind regards.Sorry, I don't know of any way to avoid referencing each column by name.
    The fact that you want to do this hints that this is a denormalized table, designed to make coding difficult and inefficient. A better design would be:
    SELECT 'A' as org, 12 as val,  1 AS col_num     FROM dual  UNION ALL
    SELECT 'A',           13,            2              FROM dual  UNION ALL
    SELECT 'A',        4,            3          FROM dual  UNION ALL
    SELECT 'A',        40,            4          FROM dual  UNION ALL
    SELECT 'A',         100,            5          FROM dual  UNION ALL
    ...Then you could use the MAX function to see if any of them were greater than 0, regardless of how many there were.
    with my_table as (
    Select 'A' as org, 12 as val_1, 13 as val_2, 14 as val_3, 40 as val_4, 100 as val_5 from dual
    union all
    Select 'b' as org, 12 as val_1, 13 as val_2, 14 as val_3, 40 as val_4, 100 as val_5 from dual
    union all
    Select 'c' as org, 12 as val_1, 13 as val_2, 14 as val_3, 40 as val_4, 100 as val_5 from dual
    union all
    Select 'A' as org, 0 as val_1, 0 as val_2, 0 as val_3, 0 as val_4, 0 as val_5 from dual)
    select * from my_table
    where
    ( val_1 != 0 And val_2 != 0 and val_3 != 0 and val_4 != 0 and val_5 != 0)That shows the rows where ALL 5 of the columns are not 0.
    If you want the rows where AT LEAST 1 of the columns are not 0, then use OR instead of AND.
    != means not equal to 0. You said you were interested in whether the columns were greater than 0, which is &gt;=.

  • Trouble with links that contain %2C (comma) in url

    I have a friend that uploaded some files to a site for her students to click on and download. They're mp3 files of classical music, many of which contain commas in their filenames.
    When uploading them, the site escapes these commas by replacing them with a "%2C". For example the file "john,paul,george,andringo.mp3" would appear as "john%2Cpaul%2Cgeorge%2Candringo.mp3".
    It seems that by doing so, Safari is unable to parse the link properly and truncates the link after "john".
    Has anyone else noticed this issue? Issue noticed on Safari Version 2.0.4 (419.3).
    I tried this on Camino and Firefox, and they are able to parse this link correctly, but not Safari.
    (Clearly, the quick fix is to rename these files without commas, but I figure this is worth bringing up on this forum.)
    2.16Ghz 17" Macbook Pro   Mac OS X (10.4.6)   1.8GHz Power Mac G5

    It always pays to name any Web based files without using any punctuation.
    FTP servers don't like them and browser based links don't always get "translated" properly.
    Jane's New CD of Music.mp3 should be:
    janesnew_cd_ofmusic.mp3
    Avoid this common problem by using "Web safe" naming schemes. Avoid any illegal characters, punctuation or spaces between names.

  • To retrview records that contais a word or a part of the word

    I am developing a web form. I wanted to give search facility to my useres.
    I wanted:
    1. I must be able to retrieve all these records that contains the search string provided by the user
    2. It ignores minor spellings mistakes (Not the bigger 1). As in google search if we write OrEcle instead of writing correctly it is still able to give us results realted to Oracle.

    investigate using the functions available in the UTL_MATCH built-in package, there's the edit distance and jaro_winkler similarity functions which are quite useful for that sort of thing.
    Without any more information though we can't write your query fory you, so we'd need you to provide
    your table definitions,
    some sample data
    what you've tried so far
    why it is insufficient.
    also: this thread has a faint homework smell about it
    also also: be aware that the NLS_IGNORE_SPELLING_MISTEAKS session parameter is not available in current versions of oracle so you will have to be very explicit in your requirements.

  • Calling stored function that contains commit from .JCX

    I would like to call a stored function (Oracle) that contains a commit, from
    a WebLogic database control (.JCX). The suggested way to call a stored
    function is to do something like:
    * @jc:sql statement::
    * SELECT MY_FUNCTION({projectID}, {staffID}) FROM DUAL
    int callMyFunction(int projectID, int staffID) throws SQLException;
    This doesn't work if the function contains a commit - I get: ORA-14552:
    cannot perform a DDL, commit or rollback inside a query or DML. I don't
    want to just get my own connection to the db in my code and call it directly
    because then I won't be using the connection pool provided by WebLogic. Is
    there a recommended way to do this? So far, the database control has taken
    care of getting connections from the pool. Can I get a connection from the
    pool explicitely and use it? How do I "return" it to the pool?
    Thanks.
    Steve

    Steve Kincer wrote:
    Thanks for the response.
    So far, I've only used the database control, so I haven't been doing any
    transaction management (rollbacks/commits) myself - I've just called methods
    in my database control and not worried it. Come to think of it, all my
    other calls are just SELECTs, so it hasn't been an issue, but I've assumed
    WebLogic or the connection pool would take care of transaction management
    for me if I coded an UPDATE function in the database control.
    What do you mean by "find and use the control API provided for
    defining/demarking
    transactions" ... what control?
    I've seen stuff in the help file about transaction management, so I can
    research that, but where do I get the connection to use for this? I'm
    thinking I should get it from the pool (rather than create my own
    connection). I saw a generated method in my database control called
    getConnection, but when I tried using it with a CallableStatement I got
    error:
    "The transaction is no longer active - status: 'Committed'. No further JDBC
    access is allowed within this transaction."This means that you are automatically being taken care of transactionally,
    and don't need to do any commit() calls.
    Joe
    >
    I guess it's pretty obvious that I'm pretty new to WebLogic.
    Thanks for your help.
    Steve
    "Joe Weinstein" <[email protected]> wrote in message
    news:[email protected]...
    Steve Kincer wrote:
    I would like to call a stored function (Oracle) that contains a commit,
    from a WebLogic database control (.JCX). The suggested way to call a
    stored function is to do something like:
    * @jc:sql statement::
    * SELECT MY_FUNCTION({projectID}, {staffID}) FROM DUAL
    int callMyFunction(int projectID, int staffID) throws SQLException;
    This doesn't work if the function contains a commit - I get: ORA-14552:
    cannot perform a DDL, commit or rollback inside a query or DML.Right. It is bad style to hide a commit in a procedure. The begin-tx
    and commit should be at the same level, above any specific SQL for the
    tx. How did you start a transaction? Are you sure you have an ongoing
    transaction?
    I don't
    want to just get my own connection to the db in my code and call it
    directly because then I won't be using the connection pool provided by
    WebLogic. Is there a recommended way to do this? So far, the database
    control has taken care of getting connections from the pool. Can I get a
    connection from the pool explicitely and use it? How do I "return" it to
    the pool?You should find and use the control API provided for defining/demarking
    transactions.
    Joe
    Thanks.
    Steve

  • Parsing a String object that contains the database details in jsp

    Hi All,
    In my project i have a model which is a bean that contains
    a method :-
    UserBean.java
    ....getUserData()
    //the database connection is written here.
    st.executeUpdate("insert ----------");
    In the servlet i am calling the bean,
    ControllerServlet.java
    UserBean ub=new UserBean();
    Object obj=ub.getUserData();
    session.putValue("something",obj); //Here the obj contains all the database datas that is used in insert query
    //By using RequestDispacher i am forwarding this request & the response
    to the jsp page
    ViewJsp.jsp
    String data=(String)session.getValue("something");
    //Here "data" now contains all the database contents that is stored using insert query in the bean
    From here i need to parse the "data" in order to display the contents
    stored in the string "data" in to a html table.
    Plz. do provide a solution for this.It is very Urgent at the moment.
    So that i will be very thankful to u.
    Thanx,
    contactananth

    ok, first of all, in getData, i assume you do a SELECT, not an INSERT,
    so your bean code should look like:
    ResultSet rs = st.executeQuery(...) // or somethig like that
    return rs; // it will contain the data you needand in the jsp you write:
    ResultSet rs = (ResultSet)session.getValue("something");
    instead of
    String data=(String)session.getValue("something");
    i assume you know how to work with a ResultSet

  • How to parse excel spread sheet contains merged cells in SharePoint 2010 sand box solution?

    Hi All,
    in my requirement i need to parse  excel file which contains merged cells. i need to get this functionality in sandbox solution. in my server i can not use interop dll or open xml.  can anybody help me on this.
    Regards,
    Venu

    Hi Venu,
    There are a couple of other threads with code samples that reads excel files from document libraries, so you can try out those if you like. You probably  have to modify them a bit to adjust to Sandbox requirements, but they should do well as starting
    points anyhow.
    https://social.technet.microsoft.com/forums/sharepoint/en-US/81d2535c-49cc-4fad-8308-39c4a33fd004/read-excel-file-for-sandbox-solution-for-office365
    http://social.msdn.microsoft.com/Forums/en/sharepointdevelopment/thread/1fce430c-5e2c-401e-ad8a-99e890d1dcef
    http://social.msdn.microsoft.com/Forums/en-US/sharepointdevelopment/thread/5b5c96d4-17fb-42ad-8c30-e184fe26c5ef
    Best Regards
    Dennis Guo
    TechNet Community Support

  • How to parse text file (.eml) to get index of line, that contains Subject, From field, and base64 decoded Body

    Hello, Dear Colleagues.
    Help me please with next deal.
    As input I have .eml file:
    x-sender: [email protected]
    x-receiver: ***************************
    Received: from ***** with Microsoft SMTPSVC(7.5.7601.17514);
    Fri, 20 Mar 2015 12:43:03 +0200
    In-Reply-To: <********@LocalDomain>
    To: *****************************
    Bcc:
    Subject: Incident ID#: 117 Something wrong, something right, something missing
    Message-ID: <*****************************@LocalDomain>
    From: [email protected]
    Date: Fri, 20 Mar 2015 12:42:55 +0200
    Content-Type: multipart/related; boundary="=_related ********************"
    References: <*******************************C@LocalDomain>
    MIME-Version: 1.0
    X-KeepSent: ****************************; name=$KeepSent; type=4
    X-Mailer: Lotus Notes Release 8.5.2FP3 July 11, 2011
    X-Disclaimed: 54023
    Return-Path: [email protected]
    X-OriginalArrivalTime: 20 Mar 2015 10:43:03.0590 (UTC) FILETIME=[A48E9C60:01D062FA]
    --=_related **********************=
    Content-Type: multipart/alternative; boundary="=_alternative &**************"
    --=_alternative ******************
    Content-Type: text/plain; charset="KOI8-R"
    Content-Transfer-Encoding: base64
    U29tZXRoaW5nIHdyb25nLCBzb21ldGhpbmcgcmlnaHQsIHNvbWV0aGluZyBtaXNzaW5nDQpTb21l
    dGhpbmcgYmxhY2ssIHNvbWV0aGluZyBsaWdodCwgc29tZXRoaW5nIGRpZmZlcmVudA0KRG9uJ3Qg
    eW91IGV2ZXIgZmVlbCB5b3UgbmVlZCB0byBzcGVhayB0byBtZSB0aGF0IHdheT8NClNvbWV0aGlu
    ZyBibGFjaywgc29tZXRoaW5nIGxpZ2h0LCBzb21ldGhpbmcgZGlmZmVyZW50DQpTb21ldGhpbmcg
    d3JvbmcsIHNvbWV0aGluZyByaWdodCwgc29tZXRoaW5nIG1pc3NpbmcNCkRvbid0IHlvdSBldmVy
    IGZlZWwgeW91IG5lZWQgdG8gc3BlYWsgdG8gbWUgdGhhdCB3YXk/IA==--=_alternative ******************
    Content-Type: text/plain; charset="KOI8-R"
    Content-Transfer-Encoding: base64
    Because position of lines changes due to email type, as output I want to get:
    1). index of line that contains: Subject, i.e. "Subject: Incident ID#: 117 Something wrong, something right, something missing"
    2). index of line that contains "From", i.e. "From: [email protected]"
    3). base64 - decoded text (body of email)
    Thanks for your help.
    Have a nice day.

    jrv,
    your script, unfortunately, always return "String not found".
    Because you file is probably not constructed the same as the copy you posted.  I was just showing you how.  You will need to adjust to the actual file.
    Outlook can open and convert  EML files. 
    ¯\_(ツ)_/¯

  • Parser - CSV files to Oracle database

    Hello all,
    I wrote a csv parser that parse csv files to micorsoft access database. Now I need to parse the dataset to oracle database. This is part of my exporter class
    class MdbExporter : IExporter
    /// <summary>
    /// Exportiert das DataSet in eine Mdb-Datei.
    /// </summary>
    /// <param name="ds">Zu exportierendes DataSet.</param>
    public void Write(DataSet ds, string[] names)
    string conStr = "Provider=Microsoft.Jet.OLEDB.4.0;" +
    "Data Source=" + names[0] + ";";
    Console.WriteLine("Exporting to database {0} ...", names[0]);
    Any ideas how can I do that?
    Thanks for any replay in advance.

    I wrote a parser that goes through several folders containing csv files, reads them and creates a dataset that contains 15 tables ( which I need for an intranet application after that). I succeed to write a MDB exporter that export this dataset to microsoft access database. Now I need an exporter that will export my dataset to ORACLE database. Below is the full code for my MDB exporter:
    public void Write(DataSet ds, string[] names)
    string conStr = "Provider=Microsoft.Jet.OLEDB.4.0;" +
    "Data Source=" + names[0] + ";";
    Console.WriteLine("Exporting to database {0} ...", names[0]);
    DbConnection connection = new OleDbConnection(conStr);
    try
    connection.Open();
    catch (DbException e)
    ConsoleEx.WriteException(true, e, "Unable to open database: {0}", names[0]);
    throw;
    DbCommand command = connection.CreateCommand();
    foreach (DataTable table in ds.Tables)
    Console.WriteLine("\tDeleting table: {0}", table.TableName);
    // delete old tables
    command.CommandText = string.Format("drop table {0}", table.TableName);
    TryExecute(command, false);
    // create new
    Console.WriteLine("\tCreating new table: {0}", table.TableName);
    string[] columnStrings = new string[table.Columns.Count];
    for (int i = 0; i < table.Columns.Count; i++)
    columnStrings[i] = "`" + table.Columns.ColumnName + "`" + " varchar";
    command.CommandText = string.Format("create table {0} ({1})",
    table.TableName, string.Join(", \n", columnStrings));
    TryExecute(command, true);
    // add rows
    for (int row = 0; row < table.Rows.Count; row++)
    for (int col = 0; col < table.Columns.Count; col++)
    columnStrings[col] = "'" + Convert.ToString(table.Rows[row].ItemArray[col]) + "'";
    command.CommandText = string.Format("insert into {0} values ({1})",
    table.TableName, string.Join(", \n", columnStrings));
    TryExecute(command, true);
    connection.Close();
    I need similar exporter to Oracle database. Starting with SQL LOADER from the beginning its really not a good in my opinion since I am almost done with this approach.
    Any help would be appreciated.
    Regards,
    Sven

  • Parse a string that uses nested string delimiters

    I’m looking for a way to parse a string that uses double quotes as the delimiter that contains a nested string with double quotes.  I want to keep the double quotes in the nested string.  Is there a function in Labview that I can use to easily do this?  Does Labview have a command line parser / interpreter?
    The string example is: While match "Send Test "Sleep 5" ">""
    The result string would be:  Send Test "Sleep 5" ">"

    Here is another solution which is slightly faster.  Speed won't be
    an issue unless you are running millions at a time, as in my test the
    difference was only 1-2 ms in 10000 iterations.  In this image the
    Match Pattern function retrieves the desired string, including the
    outside quotes, so the String Length and String Subset functions are
    used to remove the first and last characters of the result.
    Message Edited by tuba on 04-11-2006 10:35 PM
    Attachments:
    parse.gif ‏3 KB

  • Word 2007: Error when saving file that contains equations

    Using Microsoft Word 2007, version 12.0.6425.1000 with Service Pack 2
    I am a High School Math teacher, and when working on a document that contains a number of math equations. When I try to save the document, Word refuses to save. It displays the following error: "A file error has occurred. <filename>. OK",
    and I am unable to save the file. 
    Reading the forum, I have found this to be a very common issue going back to 2009, but I have not seen a definitive solution or patch. 
    I have found a workaround:
    Creat a new document
    Copy and paste from the corrupted doc each page, saving the new document after each page
    Until I hit the error, then I know the page that has the issue, and can usually narrow it down to a specific math equation. Nothing fancy just some basic math. 
    Manually rewrite the equation in the new document and it will successfully save.
    But the issue has been occurring more and more frequently now and it is becoming very frustrating. Any help would be greatly appreciated! 

    There has been a long time known issue with the equation editor.  it causes document corruption by "losing" XML tags.
    Apparently fixes for some causes of these problems have been rolled out in Windows updates. But the problem still exists.  You've got it easy. A lot of people running into this problem are students working on documents, like a thesis, that is on a short
    deadline ...
    One identified cause of these problems is editing equations
    after you created them.  DON'T DO THAT! 
    If you have to change an existing equation, create a new correct one and delete the old one.
    Simpler fix. Don't use Word (or Office) for creating equations.  Find some other product, like a pencil.
    Over in the "Answers" forum there are a couple volunteers, Tony Jollans and Jeeped
    , who have been manually fixing this type of error if you post a new question or add a reply to one of the ongoing discussions on this issue.
    Sorry.
    If you want to invest the time to figure out what your error looks like you may be able to come up with a fix other than copy /paste method.
    Can't open Word File because of end tag/start tag mismatch error... XML Tag 
    - XML Error – Fix It tool - “The name in the end tag of the element must match the element type in the start tag”
    This error is caused when Word either “forgets” to write an XML tag, or writes them in the wrong order.
    Tony Jolans was the first person that I heard of with home made tool to fix the problem. Now MS has released a Fix It for one specific variation of the problem.
    If the tools don’t fix your problem, the file will have to be fixed manually, repairing the tag order.
    The Fix It article notes that the document is still in a fragile state. You have to do some addition fixing to avoid repeats of the problem.
    https://blogs.technet.com/b/wordonenotesupport/archive/2011/03/24/error-when-opening-a-word-2007-or-2010-document.aspx
    http://support.microsoft.com/kb/2528942- FIX IT
    This fix it will work for one specific tag error where there are equations and graphics in the same paragraph AND Office 2010 SP1 has not been applied.
    Preventative suggestions
    <snip Jeeped>
    I don't think that anyone can completely stop editing equations, but pre-planning them should avoid unnecessary edits.
    While I have no concrete, reproducible evidence that editing equations is a cause, I have made these empirical observations:
    I cannot state precisely what many of the DOCX XML tags do, but basic XML syntax rules would suggest that code like:                   <m:oMath><m:e><m:ctrlPr/></m:e></m:oMath>
    ... does nothing at all since it closes everything it opens and offers no content. It looks to me that this is a result of deleting one or more characters from an equation.
    While Word 2010 reports these as a problem at:                  Line: 2  Column: 0 ... Word 2007 will still report the actual position, e.g.:                
     Line: 2  Column: 2726981 I keep a copy of Word 2007 side-by-side Word 2010 for no other purpose. It's the only Office 2007 program on my computer. This seems like it is actually a step backwards from a resolution since Word 2010 no longer seems
    to be able to parse its own error.
    Whether the syntax is truly useless and non-effective for any intent or purpose is actually beside the point. The syntax passes conformity tests and the DOCX
    should launch. Why an 85 page document is 'broken' due to a few empty XML formatting tags while retaining legal syntax structure is beyond me.
    I try to pass along the area that the problem was in and several times people have remarked that the area I report was the place they were last making modifications/deletions to equations (not additions) when the no-load corruption
    occurred.
    When no indication from the OP is offered on what was worked on last, the Line: 2 Column: 0 corruption often comes within a formula at the very end of the unfinished Word/Document.xml file and it may be inferred
    that this was the last place being worked upon.
    The corrupt DOCX files I've worked on are very commonly at the last stages of development with a large complex document. While there couldn't be a worse time for a corruption to appear, it would seem that small edits to existing content are causing
    it and not large scale new content generation.
    Not one of these points is a definitive 'smoking gun', but put together they seem to indicate
    formula editing and not formula writing as a cause for the Line: 2 Column: 0 corruption. If it looks like a duck and quacks like a duck, it is most often a duck.
    </snip>
    Copy “True Autosave Macros for Office” to this place in reply
    Let me fix it myself
    If you are familiar with editing XML, you can try to fix the problem yourself by correcting the sequence of the mismatched oMath tags in the document. See the following example:
    Incorrect tags:
    <mc:AlternateContent>
    <mc:Choice Requires=”wps”>
    <m:oMath>
    </mc:AlternateContent>
    </m:oMath>
    Correct tags:
    <m:oMath>
    <mc:AlternateContent>
    <mc:Choice Requires=”wps”>
    </mc:AlternateContent>
    </m:oMath>
    Note: You will have to use an application such as Notepad to edit the XML.
    Manual Technique
    <snip>  A DOCX document is actually a .ZIP file that contains many internal components. There is an internal folder called word which will always contain a document.xml file. This file is the basis of the document's layout
    and content.
    Assuming that the DOCX archive structure has not been corrupted, it can be opened in an archive utility. I use
    WinRAR for this. Once opened in
    WinRAR, you can drill down into the
    word folder and see the document.xml file. I use
    Notepad++ as a text editing tool and have the .xml file extension associated with this program so i can simply double-click
    document.xml in WinRAR to open an editing session.
    Notepad++ has cursor positioning in the right-hand side of the status bar and finding the position of the error (supplied by a failed open in Word) is pretty straightforward. I look for empty formatting
    tags first and only remove content if removing empty tags does not allow the document to be opened. I try to note existing content in the area that I make modifications in order that I can supply position reference information to the owner of the DOCX.
    When editing, I assume the philosophy that kess is more. My target is to get the document to open in Word with as little modification as possible and let the original owner of the DOCX make any necessary adjustments.
    I should mention that after making a change to word/document.xml you need to save it in
    Notepad++ then go to
    WinRAR and acknowledge that you want to update the file in the DOCX archive. Once the archive is updated, you can attempt to open the DOCX in Word to see if your efforts are successful.
    WinRAR                    
    Notepad++                 
    </snip>
    Further Fixes
    The Fix it solution in this article should let you recover your Word document. However, the symptoms will reappear when you make any further edits to the document unless the core problem in the structure of the document is resolved.
    To try to correct the core problem, follow one of these workarounds:
    Install Office 2010 Service Pack 1
    Office 2010 Service Pack 1 resolves this issue for new files. It will also prevent the problem from recurring with any files that were recovered with the Fix it solution in this article.
    To download Office 2010 Service Pack 1, follow the steps provided in this Microsoft knowledge base article:
    2460049 - Description of Office 2010 SP1
    Grouping Objects
    The steps provided work best under Word 2010:
    After you open the recovered document, turn on the Selection pane. This can be found in the
    Home tab of the ribbon. The editing group of the
    Home tab has a dropdown button named Select.
    Click the Select button, and then click
    Selection Pane...
    Press the Ctrl button on your keyboard and then click each text box in the selection pane.
    Click the Group button under the Format tab. This will group all the objects together.
    As soon as you have all objects grouped on each page, save the document under a new name.
    Save the document in the .RTF file format
    The steps provided work for both Word 2007 and Word 2010:
    After you open the recovered document, click File and select
    Save (for Word 2007 click the Office button and select
    Save As)
    In the Save As dialog box, click "Save as type:" dropdown and select
    Rich Text format (*.rtf).
    Click Save.
    Click to view this
    blog for more information about this issue.
    Bonus tip: Win7 Win8 Math Equation Input Panel / Math input Panel
    http://www.lytebyte.com/2009/07/24/guide-to-math-input-panel-in-windows-7/
    http://www.7tutorials.com/windows-7s-tablet-input-panel-text-entry-and-handwriting-recognition
    http://www.7tutorials.com/training-tablet-input-panel-work-even-better
    http://www.7tutorials.com/do-math-easy-way-math-input-panel
    Not an answer to the problem, just a bonus that may make it easier to input formula’s in Win7.
    Here’s another one of those didn’t-know-it-existed-until-I-clicked-it-by-accident tools in Win7. It’s called the
    Math Input Panel.
    To access it, simply click Start, and in the Search Box that appears above, type in
    Math Input Panel.
    The Window should look like this:
    Let the fine folks at Microsoft explain what it’s used for:
    “Math Input Panel uses the math recognizer that’s built into Win7 to recognize handwritten math expressions. You can then insert the recognized math into a word-processing or computational program. “
    Tony Jolan’s Automatic Fix
    Download  http://www.wordarticles.com/temp/Rebuilder.dotm Microsoft Office Word Macro-Enabled Template (.dotm) and open it.
    Click Options button on the Security warning and select Enable this content.       
    Click the Broken Documents tab at the far right of the ribbon.      
    Click the Rebuild button in the left-hand side      
    Locate and open your corrupt document in the file open dialog.
    That's it. The process will repair your document if possible and create a new document with (Rebuilt)
    appended to the filename. Be patient as it may take a few minutes. If a repair is not possible, you can then post to a public file area and someone here can attempt a manual repair.
    Manual Fix
    XML Maker V1.1 is free. It will allow you to open the document.xml file and edit it. It also marks errors and warnings. 
    I just didn’t have much luck working with it.
    A poster used XML Maker V2.1 (US$125, 30day free trial, enough for average person to fix a file)
    Notepad ++ is a good, free editor for this type of task
    Make a copy of the file
    Rename the copy from DOCX to ZIP
    Open … .ZIP/word/document.xml in notepad
    Copy the contents of the file to clipboard
    Open Word
    Paste a copy of the copied XML into Word
    (optional) the XML is one long string too hard to read, you can replace some tags, with that tag plus a para mark to break up the text to make it more people readable.
    Open an XML validator, ie this site on the internet:
    http://www.w3schools.com/xml/xml_validator.asp
    Paste another copy of the XML into the “Syntax Check Your XML” input window
    Click on “validate” button
    Copy the missing tag, ie </mc:Fallback>  (yours will be different)
    Return to word Find: mc:Fallback>  (without the </ so you find both open and closing tags). 
    Repeat find until you hit 2 open tags in a row.  Then you just have to figure out where to put the closing tag between them. 
    Look for other tags before and after a proper closing tag so you can match the problem area to a good area.
    Discussion by many affected people, a couple in discussions are also fixing problem if Tony’s fix doesn’t work
    http://social.answers.microsoft.com/Forums/en-US/wordcreate/thread/581159d0-9ebc-4522-b30c-53e33e8268e1
    Document Recovery
    http://www.wordarticles.com/Shorts/Corruption/Formats.php
    This page has the most readable description of Word file structures, DOC and DOCX, I have seen so far
    The logical structure of a Word 97‑2003 format document is one of a series of elements arranged in a hierarchy, much like a mini file system. As an example, here is the structure of a simple Word 97‑2003 (.doc) format document:
    MyDocument.doc
    1Table
    *CompObj
    Word Document
    *SummaryInformation
    *DocumentSummaryInformation
    The physical structure of the complete file bears little relation to the logical structure; it is, again, of a proprietary design, a compound, or structured storage, file. Briefly, and loosely, the separate logical elements of the file are broken up into
    blocks; these blocks are treated as individual units, which units are then organised without regard for their logical arrangement, and catalogued, catalogue and organisation detail being held alongside the blocks themselves, to enable recombination into logical
    components when necessary.
    Just to give you a flavour, here are some views of three small parts of such a document, viewed in a hex editor:
    Views of a Word 97-2003 format Document
    The logical structure of a Word 2007 format document is one of a series of elements arranged in a hierarchy, much like a mini file system. As an example, here is the structure of a simple Word 2007 (.docx) format:
    MyDocument.docx
    _rels
    rels
    docProps
    app.xml
    core.xml
    word
    _rels
    document.xml.rels
    theme
    theme1.xml
    document.xml
    settings.xml
    fontTable.xml
    webSettings.xml
    styles.xml
    [Content_Types].xml
    As briefly as before, the [Content_Types] file and the _rels folders, along with the subordinate files therein, contain information about the logical structure, and the two files in the docProps folder contain much the same as the two Information files
    in the old format. The document.xml element within the word folder holds the bulk of the document content and the other files within that same folder hold formatting details.
    So, you might say, the internal structure of a document has changed a little, so what? There are, however, other changes that make a bigger difference. The first is that, although both logical formats are conceptually similar, they are wrapped up in
    completely different ways to make a single file. Instead of the proprietary physical structure used for Word 97‑2003 format documents, a fairly standard, and open, Zip Archive format is used for Word 2007 format documents. The second change is that instead
    of using obscure binary codes, everything in Word 2007 format documents, well almost everything, is held in XML format.
    All data held as XML? In a standard Zip Package? It should be much easier to work with, then? Judge for yourself; here are some views of parts of a Word 2007 format document taken from a hex editor:
    Views of a Word 2007 format Document
    FreeFileViewer – reads 100+ text, Office, audio, video format file types – Can open some XML tag error files
    http://www.freefileviewer.com/formats.html
    Can't open Word file due to undeclared prefix, Location: Part: /word/document.xml, Line:91, Column: 49921
    The most likely cause of your particular problem is that you are missing a
    schema prefix reference within the opening <document ...> XML tag (usually the second one). Different
    schema references are required for various types of specialty content. Here is a sample opening <document ...> tag with a large number of various schema prefix codes. If I remove one or two of these, i can reproduce
    your error message.
    <w:document xmlns:ve="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:m="http://schemas.openxmlformats.org/officeDocument/2006/math"
    xmlns:v="urn:schemas-microsoft-com:vml" xmlns:wp="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing" xmlns:w10="urn:schemas-microsoft-com:office:word" xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main" xmlns:wne="http://schemas.microsoft.com/office/word/2006/wordml">
    It's impossible to blindly say exactly what you are missing but if you post an unadulterated copy of your document to a public file area (as noted above) and post the location back here, someone may be able to help. If you are going to go this route, send
    a copy that has not already been subjected to repair attempts.
    FWIW, while it may be hard to determine exactly which schema you may be missing, I do not believe that having extras causes any problems.
    BTW, you don't actually have to rename the DOCX file extension if you have an archiving program. I use WinRAR and simply
    <right-click>, Open With... to expose the archive.

  • My playlists in itunes that contained voice memos are now blank on my phone, yet they are still on the playlist in itues on my computer. any ideas

    my playlists in itunes that contained voice memos are now blank on my phone, yet they are still on the playlist in itues on my computer. any ideas
    i like to record concerts i go to a listen to them and the voice memos are how i record them

    If you still have the 'pointers' to them in iTunes then I think that it assumes that you still have them on your computer so it won't re-download them or let you copy them from your iPod - try deleting the iTunes entry for one of them and then re-try re-downloading or, with your iPod connected, File > Transfer Purchases. If it works for that one then do the same for the others.

Maybe you are looking for

  • Displaying server stored images in an air application

    Usually when I go about displaying server stored images in a regular flex application I go about it the following way:- - Create a mysql database table on a server which contains image names - Create a php file which generates all of the image namesf

  • Lock for transaction code.

    i have created screen executed with Transaction code,having few Controls inside screen. As soon as I enter action(click push button) inside the screen.(ie Transaction code), this transaction screen should be locked, and other users should not use the

  • Passing a link list to a method

    hi i have two class files first is fileIO.java and the other is the main! i want to create a linklist in main and pass it to a method in fileIO.java. the method is static.. fileRead(File dataFile, List myList) {}doesn't seem to work.. can somebody gi

  • Mac software for accounting

    Can anyone recommend an accountancy software package for mac. I'm a one-man-band limited company in video production. I want to do as much as possible myself and avoid big accountants fees. Apologies, but not sure where else to post this? Any better

  • Problem with activating integration model

    When I am trying to activate an integration model, that includes a scheduling agreement (type LF), the activation isn't successfull. It isn't blocked, but it never stops. In the screen I have a message called "determining delta model" but it never co