asp.net - Connection property has not been initialized when filling a DataSet -
so here issue:
currently trying make report show 1st , 2nd shifts, multiple days...
so if select range 6/02 - 6/04, running query 3 times... once 6/02, 6/03, , 6/04... can select shift, dates, 4:30am-4:30pm 1st shift....
currently have error, when trying put queries/calls inside loop... calculate difference of 2 dates , set them fine, connection string gives me error:
if image not easy see here text description of error:
server error in '/mfgx_test' application.
fill: selectcommand.connection property has not been initialized.
description: unhandled exception occurred during execution of current web request. please review stack trace more information error , originated in code.
exception details: system.invalidoperationexception: fill: selectcommand.connection property has not been initialized.
source error:
line 623: dim dstop1 new dataset line 624: dim datop1 new sqldataadapter(strsql, mycn1) line 625:
datop1.fill(dstop1) line 626: line 627: mycn1.close()source file: c:\inetpub\wwwroot\mfgx_test\defectsbyround.aspx.vb
line: 625
which leads me beleive wrong connection string being outside of loop... code follows (although bit cleaned easier read):
dim mycn1 new sqlconnection mycn1.connectionstring = "server=blah;database=blah;user id=blah;password=blah" mycn1.open() = 0 session("daysdiff") strsql = "blah.blah" dim dstop1 new dataset dim datop1 new sqldataadapter(strsql, mycn1) datop1.fill(dstop1) mycn1.close() mycn1 = nothing if dstop1.tables(0).rows.count > 0 spitout2(dstop1) end if txtstartdate.text = dateadd("d",1,txtstartdate.text) txtenddate.text = dateadd("d",1,txtenddate.text) next
that's because closing connection inside loop , next iteration there no open connection present , hence exception (see pointed below)
mycn1.close() mycn1 = nothing
you should declare dataset
, tableadapter
out side loop context. code should below
dim mycn1 new sqlconnection mycn1.connectionstring = "server=blah;database=blah;user id=blah; password=blah" mycn1.open() dim dstop1 new dataset dim datop1 = 0 session("daysdiff") strsql = "blah.blah" datop1 new sqldataadapter(strsql, mycn1) datop1.fill(dstop1) ....... next mycn1.close() mycn1 = nothing
Comments
Post a Comment