I would like to do is to read CSV file begin to display to datagridview. show all the rows in the CSV but only the columns between START and END.

This code below is for import all data from csv to datagridview.

If OpenFileDialog1.ShowDialog(Me) = DialogResult.OK Then

        Try
            Dim fi As New FileInfo(OpenFileDialog1.FileName)
            Dim sConnectionStringz As String = "Provider=Microsoft.Jet.OLEDB.4.0;Extended Properties=Text;Data Source=" & fi.DirectoryName
            Dim objConn As New OleDbConnection(sConnectionStringz)
            objConn.Open()
            'DataGridView1.TabIndex = 1


            Dim objCmdSelect As New OleDbCommand("SELECT * FROM " & fi.Name, objConn)
            Dim objAdapter1 As New OleDbDataAdapter
            objAdapter1.SelectCommand = objCmdSelect
            Dim objDataset1 As New DataSet
            objAdapter1.Fill(objDataset1)
            '--objAdapter1.Update(objDataset1) '--updating
            DataGridView1.DataSource = objDataset1.Tables(0).DefaultView

            objConn.Close()


        Finally


        End Try


    End If

For that you might be better off loading the rows into a datatable reading the file one line at a time. As far as I know reading a textfile like that will only take the whole file as one table.

How can i convert my code to show all data but only the column between START and END row

Here's some code I used to help someone else. It should be a fairly simple matter for you to adapt it to what you want.

If your CSV File has headers you can Just get the columns you want by the SELECT Query.

 Dim objCmdSelect As New OleDbCommand("SELECT Col1,Col2,col3... FROM " & fi.Name, objConn)

No value given for one or more required parameters. i got this error sir

Sir i need to display row 98 for example and i want to end up to row 156. How can i do sir?

I think you'll have to clarify excactly what you need. You original question says you want all the rows and only some of the columns, now you're saying you only want some of the rows. Perhaps a sample file and a sample of what you expect to extract would help.

Where line of code caused "No value given for one or more required parameters. i got this error sir" error?

As for your wanting rows 98 - 156 use the following.
cnt is an integer variable: cnt = objDataset.Tables(0).Rows.Count - 1

 For i As Integer = cnt To 0 Step -1
            If i < 98 Or i > 156 Then
                objDataset1.Tables(0).Rows(i).Delete()

            End If
        Next
        ds.Tables(0).AcceptChanges()

I would like to see a sample of your csv file the first 3 rows should be enough.

i only need to import the value starting in column B to column I, and start rows must be in column B with the word "START" and ends in the row with the word "END".

Please post some of your CSV file. We do n ot know what your column names are or what your data looks like.

need to display from start to end only

CLIENT-RD/OT HC 8   7   8   10  11  12  10
C-RD/OT 6:00    0   0   0   0   0   0   0
C-RD/OT 7:30    0   0   0   0   0   0   0
C-RD/OT 8:00    0   0   0   0   0   0   0
C-RD/OT 9:00    8   7   8   10  11  12  10
C-RD/OT 10:00   0   0   0   0   0   0   0
C-RD/OT 12:00   0   0   0   0   0   0   0
C-RD/OT 1:30    0   0   0   0   0   0   0

ML      0   0   0   0   0   0   0
VL/SIL  2   4   1   1   1   2   2
SL         1    0   1   1   1   0   0

START                   20-Jan  21-Jan  22-Jan  23-Jan  24-Jan  25-Jan  26-Jan
CEBU                     MON    TUE      WED    THU       FRI       SAT   SUN
Team Edna - Esca                            
Adarayan, Dianne          RD    RD  6:00 AM 6:00 AM 6:00 AM 6:00 AM 1:30 PM
Bacalla, Catherine        VL    VL  RD/OT 7:30  7:30 AM 7:30 AM 7:30 AM RD
Dela Cruz, Mary Ann       6:00 AM   7:30 AM RD  RD  7:30 AM 7:30 AM 6:00 AM
Dumana, John Carlos       1:30 PM   1:30 PM 1:30 PM RD  RD  1:30 PM 1:30 PM
Macabodbod, Evelyn        9:00 AM   9:00 AM 9:00 AM 9:00 AM RD  RD/OT 9:00  9:00 AM
Mariano, Kristine         1:30 PM   RD/OT 1:30  1:30 PM 1:30 PM 1:30 PM RD  7:30 AM
Santiago, Gretchen        RD/OT 7:30    6:00 AM 7:30 AM 7:30 AM 1:30 PM 1:30 PM RD
END

This is the structure of a CSV File yours loads into a datagrid but the info is all lumped together

EXTENSION,DESCRIPTION,EXECUTABLE_PATH
.001,None,C:\Program Files\7-Zip\7z.exe
.323,H.323 Internet Telephony,rundll32.exe
.386,Virtual device driver,NO DEFAULT PROGRAM SET
.3g2,3GPP2 Movie,C:\Program Files\QuickTime\QuickTimePlayer.exe
.3gp,3GPP Movie,C:\Program Files\QuickTime\QuickTimePlayer.exe
.3gp2,3GPP2 Movie,C:\Program Files\QuickTime\QuickTimePlayer.exe
.3gpp,3GPP Movie,C:\Program Files\QuickTime\QuickTimePlayer.exe
.669,Composer 669 Module,NO DEFAULT PROGRAM SET
.7z,None,C:\Program Files\7-Zip\7z.exe
.aa,None,NO DEFAULT PROGRAM SET
.aac,None,C:\Program Files\QuickTime\QuickTimePlayer.exe
.aax,None,NO DEFAULT PROGRAM SET

Anyway try the following code after you load the datatable

 For i As Integer = 0 To 9
     ds.Tables(0).Rows(i).Delete()
 Next

  ds.Tables(0).AcceptChanges()

It should remove all the rows above the START row.

With data that is such a mishmash of structure and types you'll have to explain how you want the data separated or use a delimiter in your file.

From what I can see it looks like you want the data something like this:

    CEBU                MON         TUE         WED         THU             FRI         SAT     SUN
    Team Edna - Esca
    Adarayan, Dianne    RD          RD 6:00 AM  6:00 AM     6:00 AM     6:00 AM     1:30 PM
    Bacalla, Catherine  VL          VL          RD/OT 7:30  7:30 AM     7:30 AM     7:30 AM RD
    Dela Cruz, Mary Ann 6:00 AM     7:30 AM RD  RD          7:30 AM     7:30 AM     6:00 AM
    Dumana, John Carlos 1:30 PM     1:30 PM     1:30 PM RD  RD          1:30 PM     1:30 PM
    Macabodbod, Evelyn  9:00 AM     9:00 AM     9:00 AM     9:00 AM RD  RD/OT 9:00  9:00 AM
    Mariano, Kristine   1:30 PM     RD/OT 1:30  1:30 PM     1:30 PM     1:30 PM RD  7:30 AM
    Santiago, Gretchen  RD/OT 7:30  6:00 AM     7:30 AM     7:30 AM     1:30 PM     1:30 PM RD

yup sir i want that data display only in datagridview.

Is the format I used exacxtly how you want it? What rules govern where all those extra abbreviations go. They don't seem to follow a specific pattern with 100% accuracy.

yes sir exactly. Can you help me sir

What rules govern where the abbreviations go? Some seem to go in front of the time some in back of the time and there doesn't seem to be an obvious rule governing what goes where. Without that it's almost impossible to program this.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.