想找資料嗎?到這看看也許會有收穫喔。
‧wordpress: 佈景主題 / 插件介紹 #
‧網站教學 : css新手必看 / css筆記 / seo
‧電影片單 : 驚悚 / 懸疑 / 靈異 / 動作 / 文藝 / 劇情 / 喜劇 / 紀錄 / 科幻 / 史詩 / 戰爭 / 動畫
2008/05/31

asp.net - SqlDataReader、取小數某幾位


只是簡單的幾個code,就耗費了我半天的時間。
asp.net真的讓我用的很不習慣(不禁再三無言)
web developer他唯一的好處大概就在於有「編譯」的功能吧!但是他的html設計我真的一點都不喜歡

這次第一次的進度,大概完成了90%
重點就是
1.將特定資料表的各個欄位數值從資料表中讀取出來
2.將數值換算成百分比做統計
3.將百分比依照比率製成圖片
大概就這樣

因為根本不能用到girdview那種套件工具,所以就用了SqlDataReader,我根本不會asp.net,所以找這個東西加上try & error就耗去我好多時間
然後接著換成百分比的時候小數點太多了
開始找怎麼弄成剩下兩位數,網路上的答案好多,繼續嘗試try & error

其實東西感覺真的沒有很難
但是也可以耗掉我半天的時間...
把code放上來 做個紀錄!!!
真是寫不完的程式啊 (嘆)

  1. Dim mood(8) As Double
  2.  
  3.         Dim myCommand As SqlCommand
  4.         Dim dr As SqlDataReader
  5.         Dim myConnection As New SqlConnection("server=localhost;uid=sa;pwd=;database=hh")
  6.  
  7.         myConnection.Open()
  8.         myCommand = New SqlCommand("select * from mood where mid=1", myConnection)
  9.  
  10.         dr = myCommand.ExecuteReader()
  11.         While dr.Read()
  12.             mood(0) = dr(1)
  13.             mood(1) = dr(2)
  14.             mood(2) = dr(3)
  15.             mood(3) = dr(4)
  16.             mood(4) = dr(5)
  17.             mood(5) = dr(6)
  18.             mood(6) = dr(7)
  19.             mood(7) = dr(8)
  20.             mood(8) = dr(9)
  21.         End While
  22.         dr.Close()
  23.         myConnection.Close()
  24.         Dim ave As Double
  25.         ave = Val(mood(0)) + Val(mood(1)) + Val(mood(3)) + Val(mood(4)) + Val(mood(5)) + Val(mood(6)) + Val(mood(7)) + Val(mood(8))
  26.  
  27.         Dim result(8) As Double
  28.         For i As Integer = 0 To 8
  29.             result(i) = mood(i) / ave
  30.         Next i
  31.  
  32.         Label0.Text = result(0).ToString("0.00")
  33.         Label1.Text = result(1).ToString("0.00")
  34.         Label2.Text = result(2).ToString("0.00")
  35.         Label3.Text = result(3).ToString("0.00")
  36.         Label4.Text = result(4).ToString("0.00")
  37.         Label5.Text = result(5).ToString("0.00")
  38.         Label6.Text = result(6).ToString("0.00")
  39.         Label7.Text = result(7).ToString("0.00")
  40.         Label8.Text = result(8).ToString("0.00")
  41.  
  42.         If Label0.Text > 0 Then
  43.             Image0.ImageUrl = ("http://s760502.randombeauty.net/mu.png")
  44.         End If
  45.  
  46.  
  47.     End Sub

接著要找怎麼在html裡頭接收asp.net的值
拿php來說,wp這個網誌裡頭有可以直接抓template的位置,應用在html裡頭
asp.net不知道要怎麼用
這邊有找到一個最貼切我需求的教學,但是我還是做不出來ˊˋ
ps.日落趕快來幫我:P

Related Posts with Thumbnails
人氣:2,030    
  • 引用網址:
  • 文章標籤:,
  • 上篇文章:
  • 下篇文章:

  • comment



    :wink: :-| :-x :twisted: :) 8-O :( :roll: :-P :oops: :-o :mrgreen: :lol: :idea: :-D :evil: :cry: 8) :arrow: :-? :?: :!: