database - How to use Combo Box to search a records and display them in the datagrid view in Visual Studio 2010? -


i want display data data grid view using combo box . , user has selected starting point , destination 2 combo boxes , when user clicks on button , trains selected starting point selected destination gets displayed in datagrid view .i have written code displays records database in data grid view . tell me how search database combo box , display datagrid view ? . here code

dim connstring string = "provider=microsoft.ace.oledb.12.0; data source=c:\users\amen\documents\railway.accdb" dim myconn oledbconnection dim da oledbdataadapter dim ds dataset dim tables datatablecollection dim source1 new bindingsource    private sub button1_click(byval sender system.object, byval e system.eventargs) handles button1.click     myconn = new oledbconnection     myconn.connectionstring = connstring     ds = new dataset     tables = ds.tables     da = new oledbdataadapter("select * table1", myconn)     da.fill(ds, "table1")     dim view new dataview(tables(0))     source1.datasource = view     datagridview1.datasource = view  end sub  private sub table1bindingnavigatorsaveitem_click(byval sender system.object, byval e system.eventargs)     me.validate()     me.table1bindingsource.endedit()     me.tableadaptermanager.updateall(me.railwaydataset)  end sub  private sub form4_load(byval sender system.object, byval e system.eventargs) handles mybase.load     'todo: line of code loads data 'railwaydataset.table1' table. can move, or remove it, needed.     me.table1tableadapter.fill(me.railwaydataset.table1)     'todo: line of code loads data 'railwaydataset.table1' table. can move, or remove it, needed.     me.table1tableadapter.fill(me.railwaydataset.table1)  end sub  private sub table1bindingnavigatorsaveitem_click_1(byval sender system.object, byval e system.eventargs)     me.validate()     me.table1bindingsource.endedit()     me.tableadaptermanager.updateall(me.railwaydataset)  end sub 

end class

the query being sent database wrong, need send query depending on combo box selection in sample example in c#

strsql = " select * table1 field1=  combobox1.selectedvalue ,  field2 = combobox2.selectedvalue "   sqldataadapter da = new sqldataadapter(sqlcmd)  datatable dt1 = new datatable();  da.fill(dt1) gridview.datasource = dt1 

Comments

Popular posts from this blog

javascript - AngularJS custom datepicker directive -

javascript - jQuery date picker - Disable dates after the selection from the first date picker -