如何将Datatable值中的循环转换为字符串数组 [英] How to For loop in Datatable values to string array

查看:296
本文介绍了如何将Datatable值中的循环转换为字符串数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的代码。我是Vb.net的新手。这一定非常简单,但无法快速解决这个问题





 Dim LinID()As String =没有



 如果 dsLit.Tables( 0 )。Rows.Count>  0  然后 
对于 < span class =code-keyword>每个 i As Int16 dsLit.Tables( 0 )。行
LinID(i)= dsLit.Tables( 0 )。行(i)( LILTID)。 ToString()。修剪()
下一步
结束 如果







任何人都可以帮我这个吗?

我希望Datable的值存储在数组中。如果Datatable中有5个项目,它应该在LinID数组中存储5个字符串值

解决方案

尝试:

  Dim  list  As  列表(< span class =code-keyword>   String )()
对于 每个作为 DataRow dsLit中。表( 0 )。行
list.Add(行( LILTID)。ToString()。Trim())
下一步
Dim LinId As String ()= list.ToArray()


Here is my code. I am new to Vb.net. This must be very simple but couldn't figure it out quickly


Dim LinID() As String = Nothing


If dsLit.Tables(0).Rows.Count > 0 Then
         For Each i As Int16 In dsLit.Tables(0).Rows
           LinID(i) = dsLit.Tables(0).Rows(i)("LILTID").ToString().Trim()
         Next
       End If




Can anyone help me with this?
I want value from Datable to store in array. If there are 5 items in Datatable it should store 5 string values in LinID array

解决方案

Try:

Dim list As New List(Of String)()
For Each row As DataRow In dsLit.Tables(0).Rows
    list.Add(row("LILTID").ToString().Trim())
Next
Dim LinId As String() = list.ToArray()


这篇关于如何将Datatable值中的循环转换为字符串数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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