Mada Black

Mada Black

  • NA
  • 67
  • 3k

Retrieve DataTable index column in array

Jan 12 2023 9:12 AM

Please how to find the index of the named column ( ColeName ) in DataGridView1 ..
I have a single and unique column that I put it to generate the days in months

I tried like this but in have bad result because in want to have index of column not rows

If Conne.State = 1 Then Conne.Close()
Conne.Open()
Dim Cmd As SqlClient.SqlCommand = New SqlClient.SqlCommand("SELECT Factory1 , Factory2 , Factory3 , Factory4 , Factory5 From Table_Factory", Conne)
Dim rdr As SqlClient.SqlDataReader = Cmd.ExecuteReader()
rdr.Read()
If rdr.HasRows Then
    DT.Rows(1)(ColeName) = rdr.Item(3).ToString
    DT.Rows(2)(ColeName) = rdr.Item(4).ToString
    DT.Rows(3)(ColeName) = rdr.Item(5).ToString
    DT.Rows(4)(ColeName) = rdr.Item(6).ToString
    DT.Rows(5)(ColeName) = rdr.Item(7).ToString
End If
Cmd = Nothing
rdr.Close()
Conne.Close()

 


Answers (2)