Hi, I am now want to retrieve only year from my table(summary),field name(dates). So i am facing the problem on how to display the year in combo Box. my sql statement as below. Thanks

If i put SELECT DATES, that means day,month and year will display. So, what should i put after SELECT.

con.Open()

            sql = "SELECT dates FROM summary WHERE plants = '" & yieldsummary.cbPlant.Text & "'"
            da = New OleDb.OleDbDataAdapter(sql, con)
            da.Fill(ds, "summary")

            con.Close()
            maxrow = ds.Tables("summary").Rows.Count

            For x = 0 To maxrow - 1

                cbYear.Items.Add(ds.Tables("summary").Rows(x).Item("dates"))
                cbYear1.Items.Add(ds.Tables("summary").Rows(x).Item("dates"))

            Next x
sql = "SELECT DISTINCT year(dates) as MYear FROM summary WHERE plants = '" & yieldsummary.cbPlant.Text & "'"
da = New OleDb.OleDbDataAdapter(sql, con)
Dim Dt as New DataTable
da.Fill(Dt)
cbYear.DataSource=Dt
cbYear.ValueMember="MYear"
cbYear.DisplayMember="MYear"
.....
Comments
That is how I would do it

It come out addition error "Object reference not set to an instance of an object". The code as below

sql = "SELECT DISTINCT year(dates) as MYear FROM summary WHERE plants = '" & yieldsummary.cbPlant.Text & "'"
            da = New OleDb.OleDbDataAdapter(sql, con)
            Dim Dt As New DataTable
            da.Fill(Dt)
            cbYear.DataSource = Dt
            cbYear.ValueMember = "MYear"
            cbYear.DisplayMember = "MYear"
            con.Close()

            maxrow = ds.Tables("summary").Rows.Count

            For x = 0 To maxrow - 1

                cbYear.Items.Add(ds.Tables("summary").Rows(x).Item("dates"))
                cbYear1.Items.Add(ds.Tables("summary").Rows(x).Item("dates"))

            Next x

May i know what is going wrong for the coding..

Thanks

It come out addition error "Object reference not set to an instance of an object". The code as below

sql = "SELECT DISTINCT year(dates) as MYear FROM summary WHERE plants = '" & yieldsummary.cbPlant.Text & "'"
            da = New OleDb.OleDbDataAdapter(sql, con)
            Dim Dt As New DataTable
            da.Fill(Dt)
            cbYear.DataSource = Dt
            cbYear.ValueMember = "MYear"
            cbYear.DisplayMember = "MYear"
            con.Close()

            maxrow = ds.Tables("summary").Rows.Count

            For x = 0 To maxrow - 1

                cbYear.Items.Add(ds.Tables("summary").Rows(x).Item("dates"))
                cbYear1.Items.Add(ds.Tables("summary").Rows(x).Item("dates"))

            Next x

Thanks very much........I succes to run the system alrealy.....Bingo....

May i know what is going wrong for the coding..

Thanks

Thanks.....I success to run the coding already.....Bingo....Thanks ya...

This question has already been answered. Start a new discussion instead.