Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.net 在表中拆分nvarchar_.net_Vb.net - Fatal编程技术网

.net 在表中拆分nvarchar

.net 在表中拆分nvarchar,.net,vb.net,.net,Vb.net,我有一个datatable,它返回300行数据。我想做的是找到一个特定的列,并在有“”的列中拆分该列的内容,然后在每个拆分周围添加一个,然后返回相同的数据表 以下是我迄今为止所做的工作: Private Sub SplitCellsWithAnchor(ByVal dt As DataTable) Dim BroaderTerms As String() = dr.Item("BroaderMain").ToString.Trim.Split(CType("<br /&

我有一个datatable,它返回300行数据。我想做的是找到一个特定的列,并在有“

”的列中拆分该列的内容,然后在每个拆分周围添加一个
,然后返回相同的数据表

以下是我迄今为止所做的工作:

 Private Sub SplitCellsWithAnchor(ByVal dt As DataTable)

        Dim BroaderTerms As String() = dr.Item("BroaderMain").ToString.Trim.Split(CType("<br />", Char()))
        Dim Replace As String
        For Each b As String In BroaderTerms
            If b.Trim <> "" Then
                Replace = "<a href='' target='_blank'>" & b.Trim & "</a>"
            End If
        Next
    End Sub
专用子拆分单元swithanchor(ByVal dt作为数据表)
Dim BroaderTerms As String()=dr.Item(“BroaderMain”).ToString.Trim.Split(CType(
),Char()) 替换为字符串 对于宽项中的每个b作为字符串 如果b.修剪“”,则 Replace=“” 如果结束 下一个 端接头

据我所知,我必须给它一个datatable,但我不太确定如何获取该特定列-我应该怎么做?

我假设您已经从数据库获取了数据,它存储在一个名为
MyDataTable
的表中,datatable中的列名称为
MyColumn

 ' Untested Code
 Dim MyListOfStrings as List(of String())
 For Each MyDataRow as DataRow in MyDataTable.Rows
    'Now you jsut access the column name and do what you need with it.
    Dim MyDtring as String = MyDataRow("MyColumn")
    If Not IsDbnull(MyString) Then ' Always check for null
        ' Because we don't know how many "<br /"'s there are, we loop through them all (untested code)
        Dim MyStringArray() as string = Split(MyString, "<br />")
        Dim x as Integer = 0
        While X <= MyStringArray.Length - 1
            MyStringArray(x) = "<a href='' target='_blank'>" & MyStringArray(x) & "</a>"
            x += 1
        Loop
        MyListOfStrings.Add(MyStringArray)
        ' When complete you will have 300 string arrays in the list of strings
    End If
Next
”未测试的代码
将MyListofString作为列表(字符串()的列表)进行调整
将每个MyDataRow作为MyDataTable.Rows中的DataRow
'现在您只需访问列名,并对其执行所需操作。
Dim MyDtring as String=MyDataRow(“MyColumn”)
如果不是IsDbnull(MyString),则“始终检查null”

'因为我们不知道您看到了多少个“变量”
dr
?它来自何处?此外,您希望
.Split({“
“},StringSplitOptions.None)
在该字符串上拆分。(如果后者显示错误,请告诉我们您使用的是哪个版本的Visual Studio。)太好了!在此之后,我将尝试在每个
标记处拆分字符串..并将每个拆分包装在一个a标记中