c# - Write data to textbox row by row from database -
i want display data database row row in table
how write data database each textbox row wise
(i.e) date activity1,activity2 etc next row date activity1,activyt2 etc.. how write proper loop
the code have tried getting data first row:
private void getactivity() { try { con = new oracleconnection(connection); con.open(); oraclecommand command1 = new oraclecommand("select activityid,to_char(activitydate,'dd-mon-yyyy') activitydate,title,starttime,endtime,activitytime timetaken daily_activities1 activitydate= (select min(activitydate) daily_activities1)", con); oracledatareader reader = command1.executereader(); int count = reader.fieldcount; if (reader.hasrows) { while (reader.read()) { if (date1textbox.text == "") { date1textbox.text = reader[1].tostring(); date1textbox.enabled = false; } if (d1a1textbox.text == "") { d1a1textbox.text = "title:" + reader[2].tostring() + "\n"; d1a1textbox.text += "start-time:" + reader[3].tostring() + "\n"; d1a1textbox.text += "end-time:" + reader[4].tostring() + "\n"; d1a1textbox.text += "timetaken:" + reader[5].tostring() + "\n"; d1a1textbox.enabled = false; } else { d1a1textbox.enabled = false; } if (d1a2textbox.text == "") { d1a2textbox.text = "title:" + reader[2].tostring() + "\n"; d1a2textbox.text += "start-time:" + reader[3].tostring() + "\n"; d1a2textbox.text += "end-time:" + reader[4].tostring() + "\n"; d1a2textbox.text += "timetaken:" + reader[5].tostring() + "\n"; d1a2textbox.enabled = false; } else { d1a2textbox.enabled = false; } if (d1a3textbox.text == "") { d1a3textbox.text = "title:" + reader[2].tostring() + "\n"; d1a3textbox.text += "start-time:" + reader[3].tostring() + "\n"; d1a3textbox.text += "end-time:" + reader[4].tostring() + "\n"; d1a3textbox.text += "timetaken:" + reader[5].tostring() + "\n"; d1a3textbox.enabled = false; } else { d1a3textbox.enabled = false; } if (d1a4textbox.text == "") { d1a4textbox.text = "title:" + reader[2].tostring() + "\n"; d1a4textbox.text += "start-time:" + reader[3].tostring() + "\n"; d1a4textbox.text += "end-time:" + reader[4].tostring() + "\n"; d1a4textbox.text += "timetaken:" + reader[5].tostring() + "\n"; d1a4textbox.enabled = false; } else { d1a4textbox.enabled = false; } if (d1a5textbox.text == "") { d1a5textbox.text = "title:" + reader[2].tostring() + "\n"; d1a5textbox.text += "start-time:" + reader[3].tostring() + "\n"; d1a5textbox.text += "end-time:" + reader[4].tostring() + "\n"; d1a5textbox.text += "timetaken:" + reader[5].tostring() + "\n"; d1a5textbox.enabled = false; } else { d1a5textbox.enabled = false; } if (d1a6textbox.text == "") { d1a6textbox.text = "title:" + reader[2].tostring() + "\n"; d1a6textbox.text += "start-time:" + reader[3].tostring() + "\n"; d1a6textbox.text += "end-time:" + reader[4].tostring() + "\n"; d1a6textbox.text += "timetaken:" + reader[5].tostring() + "\n"; d1a6textbox.enabled = false; } else { d1a6textbox.enabled = false; } } } con.close(); } catch (exception et) { et.tostring(); } }
@kumartyr , according needs , don't want use gridview.
so , rewrite getactivity() funtion dynamic textbox access.
private void getactivity() { try { con = new oracleconnection(connection); con.open(); oraclecommand command1 = new oraclecommand("select activityid,to_char(activitydate,'dd-mon-yyyy') activitydate,title,starttime,endtime,activitytime timetaken daily_activities1 activitydate= (select min(activitydate) daily_activities1)", con); oracledatareader reader = command1.executereader(); int count = reader.fieldcount; if (reader.hasrows) { int = 1; textbox txtdate; textbox txtda; contentplaceholder cph = (contentplaceholder)this.master.findcontrol("maincontent"); while (reader.read() && <= 6) { if (i == 1) { txtdate = (textbox)cph.findcontrol(string.format("date{0}textbox", i.tostring())); txtdate.text = reader[1].tostring(); txtdate.enabled = false; } txtda = (textbox)cph.findcontrol(string.format("d1a{0}textbox", i.tostring())); if (txtda.text == "") { txtda.text = "title:" + reader[2].tostring() + "\n"; txtda.text += "start-time:" + reader[3].tostring() + "\n"; txtda.text += "end-time:" + reader[4].tostring() + "\n"; txtda.text += "timetaken:" + reader[5].tostring() + "\n"; } txtda.enabled = false; i++; } } con.close(); } catch (exception et) { et.tostring(); } }
Comments
Post a Comment