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"
.....
commented: That is how I would do it +8

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...

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.