Saturday, 15 September 2012

ExecuteReader requires an open and available Connection. The connection's current state is closed. in vb.net please help me -



ExecuteReader requires an open and available Connection. The connection's current state is closed. in vb.net please help me -

again error in code. please help me.

'private sub btn_issue_click(byval sender system.object, byval e system.eventargs) handles btn_issue.click dim con111 new oledbconnection con111.connectionstring = "provider=microsoft.jet.oledb.4.0;data source=..\library.mdb" dim thequery string = "select * normaltransaction barcodeno=@barcode" dim cmd11 oledbcommand = new oledbcommand(thequery, con111) cmd11.parameters.addwithvalue("@barcode", txt_barcodeno.text) using reader11 oledbdatareader = cmd11.executereader() if reader11.hasrows ' book exists msgbox("book exists!", msgboxstyle.exclamation, "sims library") else ' user not exist, add together them dim cmd12 new oledb.oledbcommand if not con111.state = connectionstate.open con111.open() end if cmd12.connection = con111 cmd12.commandtext = "insert normaltransaction([regno],[name],[memtype],[department],[barcodeno],[title],[author],[accno],[booktype],[callno],[subject],[issuedate],[duedate]) values (@a1,@a2,@a3,@a4,@a5,@a6,@a7,@a8,@a9,@a10,@a11,@a12,@a13)" cmd12.parameters.addwithvalue("@a1", txt_registerno.text) cmd12.parameters.addwithvalue("@a2", txt_name.text) cmd12.parameters.addwithvalue("@a3", txt_membertype.text) cmd12.parameters.addwithvalue("@a4", txt_department.text) cmd12.parameters.addwithvalue("@a5", txt_barcodeno.text) cmd12.parameters.addwithvalue("@a6", txt_title.text) cmd12.parameters.addwithvalue("@a7", txt_author.text) cmd12.parameters.addwithvalue("@a8", txt_accession.text) cmd12.parameters.addwithvalue("@a9", txt_booktype.text) cmd12.parameters.addwithvalue("@a10", txt_callno.text) cmd12.parameters.addwithvalue("@a11", txt_subject.text) cmd12.parameters.addwithvalue("@a12", datetimepicker1.value) cmd12.parameters.addwithvalue("@a13", datetimepicker2.value) cmd12.executenonquery() con111.close() msgbox("records added!", msgboxstyle.information, "add new customer!") end if end using con111.close() end sub'

you opening connection late, needs opened before executereader-call:

'private sub btn_issue_click(byval sender system.object, byval e system.eventargs) handles btn_issue.click dim con111 new oledbconnection con111.connectionstring = "provider=microsoft.jet.oledb.4.0;data source=..\library.mdb" dim thequery string = "select * normaltransaction barcodeno=@barcode" dim cmd11 oledbcommand = new oledbcommand(thequery, con111) cmd11.parameters.addwithvalue("@barcode", txt_barcodeno.text) con111.open() using reader11 oledbdatareader = cmd11.executereader() if reader11.hasrows ' book exists msgbox("book exists!", msgboxstyle.exclamation, "sims library") else ' user not exist, add together them dim cmd12 new oledb.oledbcommand cmd12.connection = con111 cmd12.commandtext = "insert normaltransaction([regno],[name],[memtype],[department],[barcodeno],[title],[author],[accno],[booktype],[callno],[subject],[issuedate],[duedate]) values (@a1,@a2,@a3,@a4,@a5,@a6,@a7,@a8,@a9,@a10,@a11,@a12,@a13)" cmd12.parameters.addwithvalue("@a1", txt_registerno.text) cmd12.parameters.addwithvalue("@a2", txt_name.text) cmd12.parameters.addwithvalue("@a3", txt_membertype.text) cmd12.parameters.addwithvalue("@a4", txt_department.text) cmd12.parameters.addwithvalue("@a5", txt_barcodeno.text) cmd12.parameters.addwithvalue("@a6", txt_title.text) cmd12.parameters.addwithvalue("@a7", txt_author.text) cmd12.parameters.addwithvalue("@a8", txt_accession.text) cmd12.parameters.addwithvalue("@a9", txt_booktype.text) cmd12.parameters.addwithvalue("@a10", txt_callno.text) cmd12.parameters.addwithvalue("@a11", txt_subject.text) cmd12.parameters.addwithvalue("@a12", datetimepicker1.value) cmd12.parameters.addwithvalue("@a13", datetimepicker2.value) cmd12.executenonquery() con111.close() msgbox("records added!", msgboxstyle.information, "add new customer!") end if end using con111.close() end sub'

vb.net

No comments:

Post a Comment