简体   繁体   English

为数据表分配TVP值

[英]Assign datatable a value for TVP

I have had an issue I have after much stress, narrowed down to assigning a string to a datatable (cell?) 经过一番压力后,我遇到了一个问题,范围缩小到将字符串分配给数据表(单元格?)

Dim dc As New DataColumn("Col1")
dc.DataType = System.Type.GetType("System.String")
ParameterTable.Columns.Add(dc)

For i = 0 To whereInValues.Count - 1
                r = ParameterTable.NewRow
                r.Item("Col1") = whereInValues(i).ToString
                ParameterTable.Rows.Add(r)

Next

This is a small snippet of the code in question. 这是有关代码的一小段。 It's a loop iterating through the whereInValues List(Of String) containing strings for the IN() values of an SQL Statement. 这是一个循环遍历whereInValues List(Of String)的循环,该列表包含SQL语句的IN()值的字符串。

ParameterTable is my DataTable ParameterTable是我的DataTable

This is assigned to the .value property of the parameter, which is set to Structured. 这被分配给参数的.value属性,该属性设置为“结构化”。

Basically, when I set to the value of the datatable using the .ToString method of the List, it shows fine in the debugger, but doesn't return any results from the database. 基本上,当我使用List的.ToString方法设置数据表的值时,它在调试器中可以正常显示,但不会从数据库返回任何结果。 When I set the value directly like: 当我直接将值设置为:

r.Item(column) = "Barratt Homes"

It returns the correct results. 它返回正确的结果。 I have tried wrapped a CStr() around the expression, but to no effect. 我试过将CStr()包裹在表达式周围,但是没有任何效果。

What is the difference between assigning the datatable value this way? 这样分配数据表值之间有什么区别? Is .ToString to same as a System.String? .ToString是否与System.String相同?

Sorry, I have found the answer to my question. 抱歉,我已经找到问题的答案。

My code was automatically wrapping the strings of the List(Of String) with a ' character. 我的代码自动用'字符包装List(Of String)的字符串。 When using parameters you obviously doesn't need that as it forms part of the string you are searching for. 当使用参数时,您显然不需要它,因为它构成了要搜索的字符串的一部分。 So when I was assign the string manually, I didn't have these characters there. 因此,当我手动分配字符串时,那里没有这些字符。

Stupid mistake... 愚蠢的错误......

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM