String 找不到列0。向数据行添加值时vb.net中出错
在向该行添加值时,出现了一个错误。每次向datatable中的datarow添加新值时都使用for循环String 找不到列0。向数据行添加值时vb.net中出错,string,datatable,vb.net-2010,datarow,String,Datatable,Vb.net 2010,Datarow,在向该行添加值时,出现了一个错误。每次向datatable中的datarow添加新值时都使用for循环 my code ======= dt3 = ds1.Tables(0) For Each q In dt3.Rows chkphone = q("PHONE").ToString chkdphone = Regex.Replace(chkphone, "[^\d]", "")
my code
=======
dt3 = ds1.Tables(0)
For Each q In dt3.Rows
chkphone = q("PHONE").ToString
chkdphone = Regex.Replace(chkphone, "[^\d]", "")
'MessageBox.Show(chkdphone)
If (chkdphone.Length = 10) Then
Dim NTN As DataRow = dt4.NewRow
NTN(0) = chkdphone.ToString
dt4.Rows.Add(NTN)
ElseIf (chkdphone.Length >= 10) Then
rsltstring = chkdphone.Substring(chkdphone.Length - 10, 10)
Dim NTN1 As DataRow = dt4.NewRow
NTN1(0) = rsltstring.ToString
dt4.Rows.Add(NTN1)
End If
Next
when i debug the code in first itself am getting error in the line NTN(0) = chkdphone.ToString
error : could not find column 0
什么是“Dt4”?如果您尚未初始化所有列设置,则会出现nonedt4,因为它是一个数据表。在globaland中初始化,您在其中设置了列吗?感谢您的评论。我忘记为dt4初始化datacolumn。是的,我做了。答案来了。非常感谢您的回复