.NET Framework Bookmark and Share   
 index > Chart Controls for .NET Framework > error generated in using WinSamples with databinding to csv file
 

error generated in using WinSamples with databinding to csv file

I've downloaded WinSamples and experienced some of the samples perfectly well except for 'CSVDataBinding' !!
It generates during running an error : 'IndexOutofRangeException' when binding .... (it seems to me that actually the reader is not correctlty working since the number of data fields detected is only 1 while it should be 5).
It tried also with my own code derived from the sample in Visual Basic and I get the same error...:-(((

here is the code :
Imports Chrt = System.Windows.Forms.DataVisualization.Charting<br/>
Imports System.Data         ' Necessaire pour l'import de données CSV<br/>
Imports System.Data.OleDb   ' Necessaire pour l'import de données CSV<br/>
<br/>
       ' Full path to the data source file
        Dim fileCSV As String = "DataFile.csv"

        ' Create a connection string.
        Dim ConStr As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\temp\;Extended Properties=""Text;HDR=No;FMT=Delimited"""

        Dim myConnection As New OleDbConnection(ConStr)

        ' Create a database command on the connection using query
        Dim mySelectQuery As String = "Select * From " + fileCSV<br/>
        Dim myCommand As New OleDbCommand(mySelectQuery, myConnection)

        ' Open the connection and create the reader
        myCommand.Connection.Open()
        Dim myReader As OleDbDataReader = myCommand.ExecuteReader(CommandBehavior.CloseConnection)

        ' databind the reader to the chart using the DataBindXY method
         ChartJP.Series("Serie1JP").Points.DataBindXY(myReader, "0", myReader, "2")

        ' Close connection and data reader
        myReader.Close()
        myConnection.Close()
I scanned the forum and found some tips like putting the csv file name within brackets but it does not change anything.... :-(((

Help would be greatly appreciated .... thanks in advance

Nota : I'm working in a "French" windows environment (XP SP2)
  •  
phi31lip
Hi,

It seems there is no problem in the above code. Try debugging the code and find myReader.FieldCount
Please remember to click “Mark as Answer�on the post that helps you, and to click “Unmark as Answer�if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
  • Marked As Answer byphi31lip Wednesday, September 16, 2009 10:29 AM
  •  
KishorePV
Hi,

It seems there is no problem in the above code. Try debugging the code and find myReader.FieldCount
Please remember to click “Mark as Answer�on the post that helps you, and to click “Unmark as Answer�if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
  • Marked As Answer byphi31lip Wednesday, September 16, 2009 10:29 AM
  •  
KishorePV
Thx for your kind answer. I have found the origin of the problem. In the registry base, the default delimiter declared for the Jet Engine was ";" and not "," , eventhough the regional parameters were set to "," in Windows and Excel used "," as default delimiter for CSV. It seems that the extended parameter FMT command line is not basically used by the Jet Engine which reads at first what is declared in the Registry Base. Therefore to change the default delimiter you just have to change the registry value (HKEY_LOCAL_MACHINE/Software/Microsoft/Jet/4.0/Text/Format). Another way to avoid an overall change and to apply a specific delimiter to a specific file is the following : To create a file named 'schema.ini' in the same directory as your data file (named eg 'mydata.csv') To have the following 2 lines in it : [mydata.csv] Format = Delimited(toto) where toto is your wanted delimiter. Hope it will help some people around here....
phi31lip

You can use google to search for other answers

Custom Search

More Threads

• Creating a simple chart by two columns.
• MS Chart disappears after print
• StackedColumn diffrent series (columns to begin at Y-Axel 0)
• Chart controls - text histogram
• Bind chart series to object
• getting 'error creating control' in VS2008 for chart controls in page
• Multiple cursors
• Legend position calculation problem
• .Net chart change y-axis label from milliseconds to seconds
• chart with no data