Reading OleDb records into TextBox using ComboBox VB.NET -
i'm new programming. i'm trying accomplish fill in 9 textboxes in vb.net, reading access table tblklanten, using combobox (cbbnaamfirma). cannot work life of me; i've been searching 6 hours simple thing. can of help me out? i've read numerous threads on so.com , won't work me. code have now:
private sub cbbnaamfirma_selectedindexchanged(sender system.object, e system.eventargs) handles cbbnaamfirma.selectedindexchanged dim connection new oledb.oledbconnection connection.connectionstring = "provider=microsoft.ace.oledb.12.0;data source='" & application.startuppath & "\database.accdb.'" seek connection.open() dim query string query = "select adres tblklanten [naam firma] = ' " & cbbnaamfirma.text & " ' " dim cmd new oledbcommand(query, connection) dim reader oledbdatareader = cmd.executereader reader = cmd.executereader while reader.read txtadresprev.text = reader.getstring("adres") end while connection.close() grab ex oledbexception messagebox.show(ex.message) connection.dispose() end seek end sub
thank in advance. hope code block turned out alright?
the first thing alter reading database using parameterized query. notice code cannot find because add together space before , after value of combobox.
then need start employing using statement around disposable objects ensure proper closing , disposing
finally getstring method oledbdatareader wants numeric index within returned list of fields, not name of field
private sub cbbnaamfirma_selectedindexchanged(sender system.object, e system.eventargs) handles cbbnaamfirma.selectedindexchanged dim cnstring = "provider=microsoft.ace.oledb.12.0;data source=" & _ application.startuppath & "\database.accdb" dim query = "select adres tblklanten [naam firma] = ?" using connection = new oledb.oledbconnection(cnstring) using cmd = new oledbcommand(query, connection) seek connection.open() cmd.parameters.addwithvalue("@p1", cbbnaamfirma.text) using reader = cmd.executereader while reader.read dim posadres = reader.getordinal("adres") txtadresprev.text = reader.getstring(posadres) .... other text boxes other fields here..... end while end using grab ex oledbexception messagebox.show(ex.message) end seek end using end using end sub
also connection string seems wrong. no need of quotation , stray point after fielname wrong
vb.net combobox textbox oledb
No comments:
Post a Comment