JGomez Guerra053299 (Community Member) asked a question.

I have a cwe 15 when i read Excel files and use OleDbConnection so how i can fix this issue?

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


Topics (4)

No articles found
Loading

Ask the Community

Get answers, share a use case, discuss your favorite features, or get input from the community.