作者lemarulie (另一個我)
看板C_Sharp
標題[問題] 請問一個從資料庫讀資料的問題
時間Wed Nov 19 22:26:33 2008
請較一位各位大大
myCommand = new SqlCommand("select ll,mm from mytest where name='waynefish'
", myConnection);
我要從資料庫中讀出資料,並顯示於textbox上
但是現在有一個問題
當waynefish有二筆以上的時後
這時我的textbox1會變成 "第一個ll" +"第二個ll"
textbox2會變成 "第一個mm" +"第二個mm"
如果我希望把每一筆資料都存在一個單獨的textbox中,請問我該怎麼作呢?
至於我原本的寫法是這樣:
myCommand.Connection.Open();
myCommand.ExecuteNonQuery();
SqlDataReader myDataReader;
myDataReader = myCommand.ExecuteReader();
while (myDataReader.Read())
{
for (int i = 0; i < myDataReader.FieldCount; i++)
{
}
TextBox3.Text += myDataReader[0];
TextBox4.Text += myDataReader[1];
跑出來的結果就是我說的那樣,我也不知道是什麼原因
如果有寫錯的地方還麻煩大大們幫我指正一下
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 59.113.63.116
→ hpo14:用 DataTable 存結果? 然後 foreach(DataRow x in DataTabl 11/20 01:48
→ hpo14:e.Rows) { 依序填入 TextBox1 ~ n } 完工 11/20 01:49
推 DearKurt:很好奇 原po怎樣寫的 造成資料會這樣顯示 11/21 01:54
推 tomex:FindControl()依序填值 11/21 06:03
→ lemarulie:用h大的方法解決了,感謝大家的幫忙 11/21 10:59
※ 編輯: lemarulie 來自: 59.113.58.32 (11/21 11:01)