Click here to Skip to main content
15,881,588 members
Please Sign up or sign in to vote.
2.33/5 (3 votes)
See more:
hello , code project.sorry im new at this,my question is how to retrieve data from database using the combo box?,, please give the easy way to do this thing.thanks in advance code project.
Posted
Comments
Sergey Alexandrovich Kryukov 16-Feb-12 0:13am    
Using combo box?! Well, store queries in combo box list items :-)
--SA

1 solution

hai,
try this

Try
            strSql = "select col1,cl2 from table1"
'execute sql and save it in tbk1 datatabel
             tbl1 = objDb.getTable(strSql)
'add default select column
            dim drw as datarow
            drw = tbl1.NewRow
            drw.Item("col1") = "Select"

            tbl1.Rows.Add(drw)
            combo1.DataSource = tbl1
            combo1.DisplayMember = tbl1.Columns(0).Caption
            combo1.ValueMember = tbl1.Columns(1).Caption
            combo1.SelectedIndex = -1
            combo1.Text = "Select"


then

<pre lang="sql">
dim strSql as string =select * from table 2
         where   
'some condition
              If combo1.Text.ToLower.Trim <> "select" Then
            strSql &= and  table2.column= combo1.SelectedValue 
        End If
</pre>
 
Share this answer
 
Comments
amanoob 22-Feb-12 10:48am    
@Praveen2886 thanks man.help much appreciated :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900