how to set a datatable ordinal ?

  • Thread starter Thread starter Houssem12
  • Start date Start date
H

Houssem12

Guest
Hi members

please help

when i import from excel file i have 4 column filled a datatable after that

i added a new column to the datatable i name it "designation"

that column is filled from database

DT.Load(cmd789.ExecuteReader())

DT.Columns("F1").ColumnName = "Command"
DT.Columns("F2").ColumnName = "Article"


DT.Columns("F3").ColumnName = "Qte"
DT.Columns("F4").ColumnName = "PU"
DT.Columns.Add("Désignation", GetType(String))
For n = 0 To DT.Rows.Count - 1

If cn.State = ConnectionState.Open Then
cn.Close()
End If
cn.Open()
Dim cmd23 As New SqlCommand("select AR_Design from F_ARTICLE where ar_ref='" & Trim(DT.Rows(n).Item(1).ToString) & "'", cn)
Dim lbn As SqlDataReader = (cmd23.ExecuteReader)
lbn.Read()
If lbn.HasRows Then

DT.Rows(n).Item("Désignation") = lbn(0)
Else
MessageBox.Show("Article non trouvé :" & DT.Rows(n).Item(1).ToString & " BON COMMANDE : " & DT.Rows(n).Item(0).ToString)
articleExiste = True
End If

Next



DataGridView4.RowHeadersWidth = 53
DT.Columns("Désignation").SetOrdinal(2)
DataGridView4.DataSource = DT



it works fine in 1st attempt but when i reimport the excel file and generate the new column "designation" the ordinal set not work it goes to 5th column

and i want it to be the 2nd

please how i resolve it

Continue reading...
 
Back
Top