I filled in the data with datatable from excel file.
After filling in the data, I want to save the data to the database.
The problem is as follows:
Firstly, the excel columns take fixed names {“cola”,”colb”,”colc”,”cold”,”cole”,”colf”}, and they are 5 columns at a maximum, and they can be 3 or 2 or 4 or 1 .
columns are not specified.
How do I add data in Database, where is If the column does not exist in the DataTable value “-” and if it exists, then it takes its normal value after compared to the constant name of the column.
In order to determine the place of the addition
my try not work
For i = 1 To dt2.Rows.Count - 1
If dt2 Is Nothing Then
Exit For : Exit Sub
End If
Dim com As New OleDbCommand("INSERT INTO EXPORT_TB(EXPORT_a,EXPORT_b,EXPORT_c,EXPORT_d,EXPORT_e) VALUES (@EXPORT_a,@EXPORT_b,@EXPORT_c,@EXPORT_d,@EXPORT_e)", con)
'
com.Parameters.AddWithValue("@EXPORT_a", OleDbType.VarChar).Value = dt2.Rows(i).Item(0).ToString
com.Parameters.AddWithValue("@EXPORT_b", OleDbType.VarChar).Value = dt2.Rows(i).Item(1).ToString
com.Parameters.AddWithValue("@EXPORT_c", OleDbType.VarChar).Value = dt2.Rows(i).Item(2).ToString
com.Parameters.AddWithValue("@EXPORT_d", OleDbType.VarChar).Value = dt2.Rows(i).Item(3).ToString
com.Parameters.AddWithValue("@EXPORT_e", OleDbType.VarChar).Value = dt2.Rows(i).Item(4).ToString
con.Open()
com.ExecuteNonQuery()
con.Close()
Next