asp.net - Display data of the field in a Label using Function -
i have around 14 pages 6-10 questions on each true , false answers, written db 1 , 0.
i have created summary page printable contains 14 pages 6-10 questions on each want display answer question via label
i bad @ vb.net , sql on great
i managed first 1 working, display "yes or no" second 1 doesn't work
is able formulate function can call single line of code each label instead of having ton of if statements?
i'm super bad @ sql , vb , have hardly experience appreciated.
this code have, please edit needed (if right?)
imports system.data imports system.data.sqlclient public class draftprint inherits system.web.ui.page dim con new sqlconnection dim comm_id string protected sub page_load(byval sender object, byval e system.eventargs) handles me.load comm_id = request.querystring("comm").tostring con.connectionstring = "data source=yk15-ykc0201;initial catalog=testing;integrated security=true" con.open() dim cmd new sqlcommand cmd.connection = con dim str string = "select indicator, question, answer maca community_id =" + comm_id.tostring + " order indicator asc" dim adapter sqldataadapter = new sqldataadapter(str, con) dim dt_summary datatable = new datatable adapter.fill(dt_summary) dim indicator integer = dt_summary.rows(0)(0) dim question integer = dt_summary.rows(0)(1) dim answer string = dt_summary.rows(0)(2) if question = 1 , answer = false draftprint1.text = "no" else draftprint1.text = "yep" end if if indicator = 1 , question = 2 , answer = false draftprint2.text = "no" else draftprint2.text = "yep" end if
this 1 of ways solve it. can prepare in query as:
select indicator, question, case when answer = 1 , indicator = 1 "yes" /* not sure indicator lets pretend must 1 success */ else "no" end answer ...
now, 1 of way map in code order question
(assuming question number)
draftprint1.text = dt.rows(1-1)("answer").tostring() draftprint2.text = dt.rows(2-1)("answer").tostring() ......
as see, way comes db ready populate label, have map right row right label. avoid confusion use (1-1) technique. dynamic control creation based on query resultset - way wouldn't need know numbers of controls upfront.
Comments
Post a Comment