[.NET] table.Rows.Add(datarow) 在兩層迴圈中無效

看板Visual_Basic作者 (caa)時間16年前 (2009/08/16 18:39), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串1/1
程式結構大概如下 : for each ..... for each datarow("欄位1") = 值1 datarow("欄位2") = 值2 table.Rows.Add(datarow) next next 被兩層迴圈包住Add方法救無效了 但是只被一層包住就有效 但是我必須要靠這兩層迴圈去抓我要的欄位值 請問有誰知道出了什麼問題嗎? 詳細程式碼 : '宣告 Dim add_table As New DataTable add_table = ds_update_data.Tables("關鍵字條件機率統計表") add_table.Clear() '一個關鍵字 For Each row0 In ds_update_data.Tables("現象關鍵字表").Rows Dim prob As Double Dim result As String Dim keyword As String keyword = row0(1) ds_update_work.Clear() Dim da_GoBringHist As New SqlDataAdapter("select * from 歷史_ 申訴文件 where 故障現象 like '%" + keyword + "%' ", cn) da_GoBringHist.Fill(ds_update_work, "歷史申訴文件") DataGridView_m2_update_work.DataSource = ds_update_work.Tables_ ("歷史申訴文件") For Each row1 As DataRow In ds_update_data.Tables_ ("故障零件關鍵字表").Rows result = row1(1) Dim flag As Integer Dim counter As Integer counter = 0 For Each row2 In ds_update_work.Tables("歷史申訴文件").Rows flag = 0 flag = InStr(row2(2), row1(1)) If flag > 0 Then counter = counter + 1 End If Next prob = counter / ds_update_work.Tables("歷史申訴文件")_ .Rows.Count Dim dr_update As DataRow dr_update = add_table.NewRow dr_update("關鍵字") = keyword dr_update("故障零件") = "ooo" dr_update("機率") = prob dr_update("可能故障原因") = "lll" add_table.Rows.Add(dr_update) Dim cb As New SqlCommandBuilder(da_update_data_back) da_update_data_back.Update(ds_update_data,_ "關鍵字條件機率統計表") Next Next -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 125.228.233.84
文章代碼(AID): #1AX-7wvO (Visual_Basic)