
JGomez Guerra053299 (Community Member) asked a question.
this is my code
Public Function ReadExcel(filePath As String, sheetName As String) As DataTable
Dim dt As New DataTable()
Dim connectionString As String = String.Format(GetConectionString(), filePath)
Dim connection As New OleDbConnection(connectionString)
Dim dataAdapter As New OleDbDataAdapter()
Dim command As New OleDbCommand()
Try
connection.Open()
command.Connection = connection
command.CommandType = CommandType.Text
command.CommandText = "SELECT * FROM @sheetName"
'command.CommandText = String.Concat("SELECT * FROM ", sheetName)
command.Parameters.Add(New OleDbParameter("@sheetName", sheetName))
dataAdapter.SelectCommand = command
dataAdapter.Fill(dt)
Catch Ex As Exception
Throw New Exception(String.Concat("Error al leer la hoja :", sheetName, " Mensaje Tecnico: ", Ex.Message), Ex.InnerException)
Finally
command.Dispose()
dataAdapter.Dispose()
connection.Close()
connection.Dispose()
End Try
Return dt
End Function
.png)
Hi @JGomez Guerra053299 (Community Member) ,
Please review the answer I gave on this question and see if it is workable for you: https://community.veracode.com/s/question/0D53n00007fLVveCAG/i-need-your-help-wit-cwe-15
If you have any other questions, I would recommend you schedule a consultation call to discuss.
You can check out this knowledge article (https://community.veracode.com/s/article/How-to-schedule-a-consultation-call) on how to schedule a consultation call with us.
Thank you,
Boy Baukema