c# - System.Data.OleDb.OleDbException' occurred in System.Data.dll -


i'm supposed able type postcode in textbox, when program runs, supposed put street name matching postcode in textbox.

however, i'm getting error , can't solve it. error appears on line:

leesadres = adres.executereader(); 

the whole code:

using system; using system.collections.generic; using system.componentmodel; using system.data; using system.data.oledb; using system.drawing; using system.linq; using system.text; using system.threading.tasks; using system.windows.forms;  namespace windowsformsapplication12 {     public partial class form1 : form     {         public form1()         {             initializecomponent();         }          private void form1_load(object sender, eventargs e)         {          }          private void btnzoek_click(object sender, eventargs e)         {             oledbconnection con = new oledbconnection();             oledbcommand adres = new oledbcommand("select `street` `postcode` `postcode` txtpostcode.text", con);             oledbdatareader readadres;             con.connectionstring = "provider=microsoft.ace.oledb.12.0; data source = c:\\users\\name\\documents\\school\\adodotnet\\postcode.accdb";              con.open();             readadres = adres.executereader();              while (leesadres.read())             {                 txtstreet.text = leesadres.getvalue(0).tostring();             }         }     } } 

i suspect might sql command i'm not sure, have no experience sql , databases.

you misconstructing querystring in line

"select `street` `postcode` `postcode` txtpostcode.text", con 

it should

"select `street` `postcode` `postcode` '%" + txtpostcode.text+ "%'" , con 

to make code more robust , prevent sql injection, construct of form

sqlcommand cmd = new sqlcommand("select `street` `postcode` `postcode` @p1" , conn); cmd.parameters.add(p1); cmd.parameters["p1"].value = txttagnumber.text; 

also use of stringbuilder class construct actual string.


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -