Different amount of read lines depending on whether file is open or closed with OleDbDataReader and OLEDB.12

Reading the same Excel file with OleDbDataReader and the following connectionString:
conn.ConnectionString =
"Data Source='" + xlsxFile +
"';Provider=Microsoft.ACE.OLEDB.12.0;Extended Properties='Excel 12.0;HDR=YES;IMEX=1'";
I would like to  start reading Excel file at line X, I skip X-1 first lines and:
If file is closed, first row I get is the X+1 line.
Instead, if file is open, with exactly the same source code, I get Xth line!
I’m working with .net 2.0, Visual Studio 2008 and Microsoft Office Standard 2010.
Do you have any clue? Thank you in advance!
Mary

Hi mary4wpf,
I tested the code, and shown the excel data, it works well. the showing method is like below.
if (datareader.HasRows)
while (datareader.Read())
if (skipLine)
for (int j = 1; j < startIndex; j++)
datareader.Read();
skipLine = false;
string L0="";
string L1 = "";
if (datareader.IsDBNull(0))
L0 = "";
else
L0 = datareader.GetString(0);
if (datareader.IsDBNull(1))
L1 = "";
else
L1 = datareader.GetString(1);
Console.WriteLine("{0}\t{1}", L0,L1);
else
Console.WriteLine("No rows found.");
datareader.Close();
If you have something weird, could you please share the weird with us? we could help you better.
Regards,
Youjun Tang
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click
HERE to participate the survey.

Similar Messages

  • When I start firefox, i get this message ( The instruction at "0x7b9c77a9" referenced memory at "0x7b9c77a9". The memory could not be "read" ) hs anyone any idea why? I have scanned with AVG and something simply called 'Trojan Remover' and they both fin

    when I start firefox, i get this message ( The instruction at "0x7b9c77a9" referenced memory at "0x7b9c77a9". The memory could not be "read" ) hs anyone any idea why? I have scanned with AVG and something simply called 'Trojan Remover' and they both find nothing.... any advice would be greatly welcomed.. thanks
    == This happened ==
    Every time Firefox opened
    == this morning 22/07/10

    Lyall,
    I have seen this before, a long time ago (several years), and I cannot
    remember how/if we resolved it.
    If this is an impotant issue to you, I suggest that you open a case with
    BEA support.
    Regards,
    Peter.
    Got a Question? Ask BEA at http://askbea.bea.com
    The views expressed in this posting are solely those of the author, and BEA
    Systems, Inc. does not endorse any of these views.
    BEA Systems, Inc. is not responsible for the accuracy or completeness of
    the
    information provided
    and assumes no duty to correct, expand upon, delete or update any of the
    information contained in this posting.
    Lyall Pearce wrote:
    The title says it all really.
    I see other posts getting replies.
    This is a rather important issue, I have seen another post with a similar problem.
    While not being a show-stopper it certainly raises concerns.
    The application works ok until the application exits (in both development and
    executable form)
    Apparently this did not happen with Tux 7.1
    It does with 8, I do not have 7.1 so I have no workaround.
    ..Lyall

  • Hi how to read lines in a text file???

    Hi experts
    please help me out
    i wanna read a file which contaning students id and name.
    such as
    211 john
    122 david
    111 Chris
    and so on.
    i know how to read using bufferedreder but the problem is
    my teacher is gonna change the number of students in the file
    when she marks my code....
    so i don't know how many lines(students) will it be.in the file.....
    in this case, how to read a file?? i don't know how many lines will it be..
    but i know the maximum students in the file is 20.
    how to do it with this..........................
    experts~ please help me~~~

    try this
    try {
                FileReader reader = new FileReader(f);
                BufferedReader bufferedReader = new BufferedReader(reader);
                line = bufferedReader.readLine();
                while (line !=null) {
                    line = bufferedReader.readLine();
                bufferedReader.close();
                reader.close();
            catch(IOException e) {
                String msg = new String("Error Reading " + f + " data file");
                throw new OpenFileException(msg);
            }

  • Read line N from a File

    Hi!
    I don't now how can I read for example line number 5 of a file, this is the way I do , but it doesn't work. What the programme should do is read the first line and then read line number 5, but it read line number 2!!!
    Could someone help me or paste a code ?
    This is my code:
    file = new File("fich");
    try{
    fileR = new FileReader(file);     
    catch(FileNotFoundException e){}
    BufferedReader bfr = new BufferedReader(fileR);
    LineNumberReader lnr = new LineNumberReader(bfr);
    String line=null;
    line=lnr.readLine();
    System.out.println("Line number:: " + lnr.getLineNumber());
    System.out.println(" ----> " + line);
    lnr.setLineNumber(5);
    System.out.println("Line number:: " + lnr.getLineNumber());
    line=lnr.readLine();
    System.out.println("Line number:: " + lnr.getLineNumber());
    System.out.println(" ----> " + line);
    Thanks
    Andreia

    I was looking through the bug reports (see 4178689) and this is what I found in the answer:
    "The line number kept in LineNumberReader is not the same as the physical line
    number in the input file. It is just a local counter in the reader. Setting
    this number only results in the reader start counting from a new number from
    the next readLine(), it does not allow jumping from one line to another in
    the physical data file. The readLine() call just read lines one after another
    from the underlying stream, unless reset() or skip() is called."
    rbelovoskey presented a quick work-around:
    public void navigateForwardToLine(LineNumberReader lineNumberReaderIn, int intLineToGoTo)
    int intInitialLine = lineNumberReaderIn.getLineNumber();
    try{
       for( int intCurrentLine = intInitialLine; intCurrentLine < intLineToGoTo; intCurrentLine++)
            lineNumberReaderIn.readLine();
       }catch(IOException ioe){
         ioe.printStackTrace();

  • Read This First If You Are Having a BASIC Issue with Importing and Burning!

    Most people who are new to iTunes and are not computer saavy find that their issues with burning and more typically importing are due to their security software "fighting iTunes". In most cases this is not apparent with an error message but just causes very slow sluggish performance and looks on importing as if the songs never import. Therefore an initial place to check is to disable your security system (make sure you are not connected to the internet and remember to enable upon completion!)and try to import. In many many cases users find that this corrects their problem. I have found that this is the issue 80% of the time when helping people with import issues from CD's. For some reason this is a much more prevalent issue with iTunes 6.0 than previous versions. Try it - You may like it.
    HP Pavilion 7905   Windows XP  

    Read the comment!

  • Read lines of a text file, From bottom to top

    read the last row first,
    from bottom to top,
    how to do it?
    Thanks for help

    If the index.txt contains
    1
    2
    3I want to save it as
    3
    2
    1But I got is
    1
    2
    3 3 2 1Please see my code, thanks
    import java.io.*;
    import java.util.List;
    import java.util.ArrayList;
    public class Reverse {
        private String[] x;
        public void process(String dir) {
            try {
             File f1 = new File(dir,"index.txt");
                    BufferedReader br = new BufferedReader(new FileReader(f1));
                    String line;
                    List<String> idList = new ArrayList<String>();
                    while (((line=br.readLine())!=null)){
                        idList.add(line);
                    x = idList.toArray(new String[idList.size()]);
                    f1.delete();
            catch (Exception e)
                   System.err.println("File input error");
                   e.printStackTrace ();
             try {    
             File fileIndex = new File(dir,"index.txt");
                     FileWriter outFileIndex = new FileWriter(fileIndex,true);
                     BufferedWriter outIndex = new BufferedWriter(outFileIndex);
                     for (int i = x.length-1 ; i>0; i--) {
                        StringBuffer buffer = new StringBuffer();
                        buffer.append(x);
    buffer.append("\n");
    outIndex.write(buffer.toString());
    outIndex.flush();
    catch (Exception e)
    System.err.println("File input error");
    e.printStackTrace ();
    public static void main(String args[])
    Reverse r = new Reverse();
    r.process(args[0]);

  • I have somehow erased the line at the top of my screen that starts with "http:" and where you type in a web address

    I have somehow erased the top screen line that starts with http:/     Can someone help ??

    Go to the View menu and select show Toolbar.

  • I have lost the top three lines (toolbars?), containing File, Edit, etc; back button, home, etc; and most visited, etc. How can I get them back?

    Somehow, I have deleted the top three rows from my home page. All I have left is the AOL home page. I need to get back the "File, Edit, View,etc." line, and the "Page back arrow, Home icon, etc."

    * In Firefox 3.6 versions on Windows and Firefox 4 on Windows and Linux it's possible to hide the "Menu Bar" via "View > Toolbars" or via the right-click context menu of a toolbar.
    * Press F10 or press and hold the Alt key down to bring up the "Menu Bar" temporarily.
    * Go to "View > Toolbars" or right-click the "Menu Bar" or press Alt+V T to select which toolbars to show or hide (click on an entry to toggle the state).
    See also:
    * [[Menu bar is missing]]
    * http://kb.mozillazine.org/Toolbar_customization

  • How can I prevent my screen getting covered with black and white lines while working on the internet which only happens with firefox and only go when I 'go back' or go down a page?

    It happens as I surf - horizontal black and white lines particularly when I scroll down and only goes if I can go to a new page or go back a page. It is driving me crazy and only happens with firefox. I have disabled all plug ins but it still happens.

    Try to disable hardware acceleration.
    *Tools > Options > Advanced > General > Browsing: "Use hardware acceleration when available"
    If disabling hardware acceleration works then check if there is an update available for your graphics display driver.
    *https://support.mozilla.org/kb/how-do-i-upgrade-my-graphics-drivers

  • Read a specific line of a txt file using vba not using line by line, Leer una Linea especifica de archivo de texto sin recorrer linea por linea

    Buenos días - Good morning
    Mi pregunta la escribiré en español y en ingles y espero alguien tenga la solución.
    I'll write my question in Spanish and English and I hope someone has the solution.
    SPANISH
    Creé una Macro en VBA que lee mas de 200.000 archivos de texto (.txt) los cuales tienen diferentes tamaños y cantidad de información dentro de ellos, de cada archivo necesito extraer la información de las 3 primeras lineas y las ultimas 10 lineas, las 3
    primeras lineas es fácil ya que uso un "READLINE" 3 veces y voy capturando la información de las tres primeras lineas, para las ultimas 10 lineas las cuales están identificadas por un código inicial hago un ciclo que lee linea por linea hasta que
    encuentra el numero 3 en un espacio especificado de la linea y de ahí captura la información de cada linea de texto que serian las 10 ultimas, el problema que tengo es que la cantidad de archivos y de información dentro de los archivos aumenta considerablemente
    cada día y por tener el ciclo que lee cada una de las lineas de cada archivo de texto la Macro se demora cada vez mas a medida que aumenta la información y consume cada vez mas memoria de la maquina.
    Necesito un método diferente que no lea linea por linea y que yo le pueda decir lea la linea (renglón) numero 1000 (ejemplo) y capture la información a partir de ahí para ahorrar algo de tiempo, o saber cuantas lineas de texto tiene el archivo .txt y decirle
    que me lea a partir de (numero total de lineas del txt -(menos) 10 lineas) así me leería las 10 ultimas.
    ENGLISH
    I created a Macro in VBA that reads more than 200,000 text files (.txt) which have different sizes and quantity of information within them, each file need to extract the information from the first 3 lines and last 10 lines, 3 first lines is easy as using a
    'READLINE "3 times and am capturing information from the first three lines, for the last 10 lines which are identified by an initial code I make a loop that reads line by line until it finds the number 3 in a specified area of ​​the line and then capture
    the information of each line of text that would be 10 last, the problem that I have is that the number of files and information within files significantly increases every day and having the loop that reads each line of each text file is delayed Macro increasingly
    as more information and consume more and more memory on the machine.
    I Need a different method not read line by line and I can tell you read the line (row) number 1000 (example) and capture the information from there to save some time or know how many lines of text have the file .txt and tell me read from (total number of lines
    of txt - (minus) 10 lines) so I would read 10 last.
    Here is the code I currently use
    Dejo el código que uso actualmente
    Dim fs, f, ts, REG
    Set fso = CreateObject("Scripting.FileSystemObject")
        On Error Resume Next
    sFilePath = strFolder & "\" & strFileName
    Set f = fso.getFile(sFilePath)
    Set ts = f.OpenAsTextStream(1, 0)
    REG = ts.READLINE
    Ciclo para llegar hasta las ultimas 10 lineas
    Cycle to reach the last 10 lines
    For J = 1 To 200000
                REG = ts.READLINE
                    If Val(Mid(REG, 6, 1)) = 3 Then

    Good Morning ryguy72
    First thank you so much for your answer, sorry for my english in the question, I tried for a long time to make a code that wasn't so slow to read the last 10 lines, 'cuz most codes used a cycle "For" to read line by line asking if in the specific
    position is the character(number) that tells me that i should get started to read the last lines that i need, that takes a lot longer than your code doing a Split with Mydata and storing it in strData(). I don't know how to do this and every forum that
    i consulted to read the last 10 lines quickly they made the same read line by line with a Cycle "for".
    Thanks again, I gonna improve my code with your help, 'cuz it took about 4 hours to read all the information and everyday ascended more time and memory consumption.
    Thanks to everyone who offered their help so disinterested and free, so should always be people with that spirit, I hope someday to be SO good as you programming.

  • How to select and read #define lines from a code file

    Hi,
    I would like to read a .m file
    and select the lines which begins with '#define PL-KEY', like
    {quote}
    #define PL-KEYTAG TAG_values
    #define PL-KEYGROUP GROUP_value
    #define PL-KEYINFO "INFO_ValueTxtMax120Char" // could be max 120 char
    ..... more PL-KEY keys
    {quote}
    and put the rest of that line until a '//' or '/*' , like
    {quote}
    TAG TAG_values
    GROUP GROUP_value
    INFO "INFO_ValueTxtMax120Char"
    {quote}
    into something like a list where my code above will loop through.
    I thought using something like
    cat "path/to/code.h" | while read line
    do
    #... what do I have to with "$line" ...
    if [[ "$line" == #define PL-KEY* ]] ; then
    # yes then... then what????
    done
    any suggestions?? I noticed today, I am still no shell expert
    Thanks again

    I can't help much with PlistBuddy, as I just recently found out about it myself.
    But for the code, here are some adjustments based on your comments.
    I stuck with shell scripting because you seem to be more comfortable with shell scripting, vs awk or perl.
    #!/usr/bin/env bash
    while read lb_def rest
    do
    if [[ "$lb_def" = #define && "$rest" = PL_KEY* ]]; then
    rest=${rest#PL_KEY}
    echo "${rest%/[/]}"
    fi
    if [[ "$lb_def" = # && "$rest" = define PL_KEY* ]]; then
    rest=${rest#define }
    rest=${rest#PL_KEY}
    echo "${rest%/[/]}"
    fi
    done </path/to/code.h
    If PL_KEY has stuff in front if it, like one of your posts where it was kPL_KEY, then you could modify the uses of PL_KEY to include the 'k', or you could wildcard it. If a single character, then
    if [[ "$lb_def" = #define && "$rest" = ?PL_KEY* ]]; then
    rest=${rest#?PL_KEY}
    If multiple characters could prefix PL_KEY, then you can use the multi-character wildcard
    if [[ "$lb_def" = #define && "$rest" = PL_KEY ]]; then
    rest=${rest#*PL_KEY}
    If you are worried, that PL_KEY might exist in the comment, then you could strip the comment before doing the tests
    #!/usr/bin/env bash
    while read lb_def rest
    do
    rest=${rest%/[/]} # remove comments.
    if [[ "$lb_def" = #define && "$rest" = PL_KEY ]]; then
    rest=${rest#*PL_KEY}
    echo "${rest}"
    fi
    if [[ "$lb_def" = # && "$rest" = define PL_KEY ]]; then
    rest=${rest#define }
    rest=${rest#*PL_KEY}
    echo "${rest}"
    fi
    done </path/to/code.h
    Is that better?
    Message was edited by: BobHarris

  • HT3702 They charged to my credit card different amount

    On Monday September 23 I just made one transaction for 1.99 and they charged me different amount two time, can u fix it for me please

    To Contact iTunes Customer Service and request assistance
    Use this Link  >  Apple  Support  iTunes Store  Contact

  • Shell scripts to read data from a text file and to load it into a table

    Hi All,
    I have a text file consisting of rows and columns as follows,
    GEF001 000093625 MKL002510 000001 000000 000000 000000 000000 000000 000001
    GEF001 000093625 MKL003604 000001 000000 000000 000000 000000 000000 000001
    GEF001 000093625 MKL005675 000001 000000 000000 000000 000000 000000 000001 My requirement is that, i should read the first 3 columns of this file using a shell script and then i have to insert the data into a table consisting of 3 rows in oracle .
    the whole application is deployed in unix and that text file comes from mainframe. am working in the unix side of the application and i cant access the data directly from the mainframe. so am required to write a script which reads the data from text file which is placed in certain location and i have to load it to oracle database.
    so I can't use SQL * loader.
    Please help me something with this...
    Thanks in advance.

    1. Create a dictionary object in Oracle and assign it to the folder where your file resides
    2. Write a little procedure which opens the file in the newly created directory object using ULT_FILE and inside the FOR LOOP and do INSERTs to table you want
    3. Create a shell script and call that procedure
    You can use the post in my Blog for such issues
    [Using Oracle UTL_FILE, UTL_SMTP packages and Linux Shell Scripting and Cron utility together|http://kamranagayev.wordpress.com/2009/02/23/using-oracle-utl_file-utl_smtp-packages-and-linux-shell-scripting-and-cron-utility-together-2/]
    Kamran Agayev A. (10g OCP)
    http://kamranagayev.wordpress.com

  • Dyanamic table is SAP Script with horizontal and vertical lines

    Hi,
    I need to display the data of the table in the SAP script which is having both horiziontal and vertival lines.
    the out put needs to looks as it in Excel...where there are multiple records with 5 fixed coulmns each seprated from one another by horizonalt and vertical lines..
    I thinking about useing the Box with XPOS and YPOS who value changes dynamicaaly..
    But again as the number of pages might be more than one..i think there will issues,
    Can you  let me know how to proceed in SCRIPT ,,,, where the number of records might vary ..and also ..it might continue to second page..
    Regards
    Senthil

    well it is possible but quite tricky.
    All you got in SAP-SCRIPT to achieve this is the BOX-Statement.
    The BOX statement works with variables for XPOS, YPOS, WIDTH and HEIGHT. what you need to do is:
    - calculate those variables during runtime
    - add box-statements with those variables.
    to calculate those variables you need to count used lines and so on. i hope i showed you a way, rest is a lil brainwork then.
    regards

  • Kinect Explorer WPF C# read depth data from the file and conversion to skeleton

    Hello,
    I am using Kinect sensor to do some research on biometrics. Since it is impossible to find people to collect some samples, I would like to use samples from the TUM - GAID database, where there exist Color View and Depth View (in .raw format) samples. Therefore,
    I need to read these samples from the file and do a batch processing, instead of performing real-time collecting of samples (where I can take automatically the Skeleton view using the Kinect SDK). So, I need help on
    1. Reading the data from the file (instead of activating the Kinect sensor) and give this data as an input for conversion to a skeleton
    2. Read the .raw files 
    Thank you very much
    Kind regards

    Hiya,
     I doubt this forum, C Sharp, will provide much help. You are asking about the Kinects system not C#
    language. However, you can try this link; http://kinectforwindows.codeplex.com/
    Hope this help. Thanks :)

Maybe you are looking for

  • Is it possible to get an apple ID without having to put a way of payment?

    Well not everyine has a visa card or any other kind of card and since there are free apps in the app store it seems natural that we get the ability to creat an apple ID and download free games without having to have a visa card (since it is useless f

  • Registers used to record sales and taxes

    Hi all, I want to know which registers are used to record the sales revenues and the taxes. for ex RG23. regards, Vikrant

  • Can I use morethen one faces-config.xml

    HI, now I am learning jsf, I have a doubt that ,can I use more than on faces-config.xml in one application ? and can we cahange name of faces-config.xml to faces-config-first.xml, and faces-config-second.xml? if it is possible , what should i do? Tha

  • Calling c program from oracle

    Hi i have a c program in SOlaris box..how to call it frm PLSQL and return a value from tht..can any one guide me..its urgent?????????

  • View/access log4j application logfile from oj4jadmin

    hi, the application logging is configured by log4j.xml as follows: <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE log4j:configuration SYSTEM "log4j.dtd"> <log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/"> <appender name="FILE_APP