[英]A DataTable which having id from other datatables, Need to transform this datatable to replace ids with their datatable name column value
[英]Getting value from field in DataTable when column name has spaces
我努力了:
ObjDTOleDBNFeIntegra.Rows(I)("[Cnpj Cpf]").ToString() //with brackets
ObjDTOleDBNFeIntegra.Rows(I)("'Cnpj Cpf'").ToString() //with apostrophe
ObjDTOleDBNFeIntegra.Rows(I)("Cnpj Cpf").ToString() //without anything
我正在使用VB.NET,但這里的撇號注釋似乎沒有被識別出來。
我得到每個案例的例外情況:
列'[Cnpj Cpf]'不屬於表Table。 (失敗) 列'Cnpj Cpf'不屬於表Table。 (失敗) 列''Cnpj Cpf''不屬於表Table。 (失敗)
當列名有空格時,我應該怎么做才能從dataTable中的字段中獲取值?
你有沒看過專欄認為它叫什么? 例如,它可能有下划線。 循環遍歷列並查找(抱歉,C#中的示例):
foreach(DataColumn col in table.Columns) {
Debug.WriteLine(col.ColumnName);
}
實際上,如果你在循環中使用它,使用該列會更快,所以我可能會使用類似的東西:
DataColumn col = table.Columns["whatever"];
foreach(DataRow row in table.Rows) {
Console.WriteLine(row[col]);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.