Re: By name and not By index
Quote:
Originally Posted by 24sharon
when I want to change parameters in column I have to write the index of the column and not the name
for example
this code work good
Dim dtchild As DataTable = New DataTable
dtchild.Columns.Add("cID", GetType(System.Int32))
dtfather.Columns(1).Unique = True
but here I get error
Dim dtchild As DataTable = New DataTable
dtchild.Columns.Add("cID", GetType(System.Int32))
dtfather.Columns("cID").Unique = True
the Same problem with dataTable
this code is OK
For Each ro In ds.Tables(0).Rows
and here I got error
For Each ro In ds.Tables("dtfather").Rows
how can I use the name and not the indexes?
thanks alot
dunno what happend to your machine but it works in my machine
VB Code:
Dim ds As New DataSet()
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
values()
Me.DataGrid1.DataSource = ds.Tables("dt")
Dim r As DataRow
For Each r In ds.Tables("dt").Rows
MessageBox.Show(r(0).ToString)
Next
End Sub
Sub values()
Dim s() As String = {"awe3cg", "waheh", "askdjf", "lkajsd"}
ds.Tables.Add("dt")
ds.Tables("dt").Columns.Add("name")
ds.Tables("dt").Columns("name").Unique = True
Dim i As Integer
For i = 0 To UBound(s)
Dim d As DataRow = ds.Tables("dt").NewRow
d(0) = s(i)
ds.Tables("dt").Rows.Add(d)
Next
End Sub
Re: By name and not By index
mar_zim
Thanks!
did someone know the replay to my second question?