位置3没有行 [英] There is no row at position 3

查看:78
本文介绍了位置3没有行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对,我使用此代码将gridview数据集转换为新的datable.
然后,当DEPT单元格的某些行与变量prodName满足相同条件时,它将删除数据行.
如果dtDeleteSh仅包含1行,则此代码有效.但是,具有超过1个数据行的数据表将显示错误位置1/2/3处无行"

Hye, I use this code to convert gridview dataset into new datable.
Then when certain row for DEPT cell meets same condition as variable prodName,it will delete the datarow.
If dtDeleteSh contains only 1 row, this codes work. However datatable with more than 1 datarow will display an error "There is no row at position 1/2/3"

Dim dtDeleteSh As New DataTable
                         dtDeleteSh.Columns.Add("check")
                         dtDeleteSh.Columns.Add("DEPT")
                         dtDeleteSh.Columns.Add("NAME_T")
                         dtDeleteSh.Columns.Add("EMPID_T")



For shRow As Integer = 0 To gdShop.Rows.Count - 1

      Dim rowdeleteSh As DataRow = dtDeleteSh.NewRow()
      rowdeleteSh = dtDeleteSh.NewRow
      rowdeleteSh("check") = gdShop.Rows(shRow).Cells(0).Text
      rowdeleteSh("DEPT") = gdShop.Rows(shRow).Cells(1).Text
      rowdeleteSh("EMPID_T") = gdShop.Rows(shRow).Cells(2).Text
      rowdeleteSh("NAME_T") = gdShop.Rows(shRow).Cells(3).Text

      dtDeleteSh.Rows.Add(rowdeleteSh)

Next


For countSh As Integer = 0 To dtDeleteSh.Rows.Count - 1


     If prodName = dtDeleteSh.Rows(countSh)("DEPT").ToString Then
             dtDeleteSh.Rows(countSh).Delete()

     End If
Next


     gdShop.DataSource = dtDeleteSh
     gdShop.DataBind()



错误发生在这里



The error occurs here

If prodName = dtDeleteSh.Rows(countSh)("DEPT").ToString Then

推荐答案

尝试将此C#,plz转换为VB.net,我做了一些转换提示尝试:
try this c#, plz convert to VB.net, I did some conversion hints try:
dtDeleteSh =   dtDeleteSh.AsEnumerable().Where(a => a["DEPT"].ToString()!=prodName ).CopyToDataTable();




vb示例:(不知道它的正确语法)




Sample vb:(dont know it''s correct syntax)

dtDeleteSh = (From del In dtDeleteSh _
Where del!DEPT.ToString <> prodName _
Select del).CopyToDataTable()



逻辑是选择要保留的行,并避免将其删除并将其重新分配给现有数据表.



the logic is select rows that are to keep and avoid the one''s to delete and reassign this to existing datatable.


这篇关于位置3没有行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆