Hi friends, after a long time. i am developing a small tool by using VB.Net. I want to display data in comboboxes from a table which is in an access database. I using SQL query. Its a simple problem , I think the problem is in my COMMAND. I want to display data as DISTINCT(No repeating data). I am including the code and design form. If u can pls help me..
My code(for form) is
///
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
cn = New Data.OleDb.OleDbConnection
cn.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=\\CTCRI-STUDENTS\Rajeev R Nair\Rajeev.Dept.ESS\Variety Finder\Variety Finder\Tuber.accdb"
sql = "SELECT DISTINCT plt_type, mature_stm_clr, emerging_l_c, leaf_type, petiole_color, flower_nature, tuber_shape, tsc, trc, tfc, pre_tuber_neck, Any_other FROM cassava"
cmd = New Data.OleDb.OleDbCommand(sql, cn)
ad = New System.Data.OleDb.OleDbDataAdapter(sql, cn)
Try
cn.Open()
cmd = New Data.OleDb.OleDbCommand(cmd.CommandText, cn)
rd = cmd.ExecuteReader
' ad.Fill(ds, "cassava")
While (rd.Read)
ComboBox1.Items.Add(rd(0))
ComboBox2.Items.Add(rd("mature_stm_clr"))
ComboBox3.Items.Add(rd.Item("emerging_l_c"))
ComboBox4.Items.Add(rd.Item("leaf_type"))
ComboBox5.Items.Add(rd.Item("petiole_color"))
ComboBox6.Items.Add(rd.Item("flower_nature"))
ComboBox7.Items.Add(rd.Item("tuber_shape"))
ComboBox8.Items.Add(rd.Item("tsc"))
ComboBox9.Items.Add(rd.Item("trc"))
ComboBox10.Items.Add(rd.Item("tfc"))
ComboBox11.Items.Add(rd.Item("pre_tuber_neck"))
ComboBox12.Items.Add(rd.Item("Any_other"))
End While
rd.Close()
cmd.Dispose()
cn.Close()
Catch ex As Exception
MsgBox("Cannot open connection")
End Try
ComboBox1.SelectedIndex = 0
ComboBox2.SelectedIndex = 0
ComboBox3.SelectedIndex = 0
ComboBox4.SelectedIndex = 0
ComboBox6.SelectedIndex = 0
ComboBox5.SelectedIndex = 0
ComboBox7.SelectedIndex = 0
ComboBox8.SelectedIndex = 0
ComboBox9.SelectedIndex = 0
ComboBox10.SelectedIndex = 0
ComboBox11.SelectedIndex = 0
ComboBox12.SelectedIndex = 0
End Sub
///
I am attaching the image of form in design and my sample database. Please help me immediately.
Yours Truly Rajeev.