vb.net - Need to Extend the Scope of a DataTable -
i'm converting old vb 7 code used odbc connect sql anywhere db vb 2013 , access 2010 db.
i declare several datasets @ top of module when procedures , functions, have lost scope of datatable.
i have next declared:
public con new system.data.oledb.oledbconnection("provider=microsoft.ace.oledb.12.0;data source=|datadirectory|\cli_crvm.accdb") public extractda new oledbdataadapter("select * [extract]", con) public extractcb = new oledbcommandbuilder(extractda) public extractdt datatable public extractdr datarow
then, in clicked event of button, phone call procedure loads datatable:
extractcb.quoteprefix = "[" extractcb.quotesuffix = "]" extractdt = new datatable extractda.fill(extractdt)
when returns clicked event code, each loop:
for each extractdr system.data.datarow in extractdt.rows
at point, can see values datatable this:
ls_plan_code = trim(extractdr("plan_code")) msgbox("plan code: " & ls_plan_code)
but when phone call procedure or function need values datatable, no longer available. ie. when executes:
sub accumulation(byval adec_premium decimal, byval ai_stage integer) dim ldec_mode decimal ldec_mode = cdec(extractdr("pay_mode")) end sub
i error: "object reference not set instance of object."
i know workaround pass datarow sub routine; however, there several datatables , many procedures , functions, of phone call other procedures , functions rely on info other datatables. additionally, sub routines write values reply datatable gets written access db.
so, while know may not "proper" form, i've got code , running test values , if there way - did in vb 7 code - scope of datatable extend throughout entire module, think problems solved.
thanks in advance!
in next line:
for each extractdr system.data.datarow in extractdt.rows
by specifying extractdr system.data.datarow
, creating new variable. variable beingness assigned value instead of variable same name in higher scope.
simply remove as system.data.datarow
:
for each extractdr in extractdt.rows
vb.net datatable scope ms-access-2010
No comments:
Post a Comment