Use a TextFieldParser to read the file and populate a DataTable. The MSDN documentation for the class has code examples. You can then use a DataAdapter to save the data to the database.
So what have you got so far? If we see that then we can help you extend it. For myself, I'm not keen on just providing code from the outset but, if I see effort, I'm more than happy to provide assistance, whether that be guidance, code or both.
I am trying with below code, and now I am trying to fetch the value and trying for inserting it in Oracle database. Thanks for the help.
Using myReader AsNew Microsoft.VisualBasic.FileIO.TextFieldParser("C:\TEST\test.txt")
myReader.TextFieldType = FileIO.FieldType.Delimited
myReader.SetDelimiters("|") Dim currentRow AsString() WhileNot myReader.EndOfData Try currentRow = myReader.ReadFields() Dim currentField AsString ForEach currentField In currentRow
MsgBox(currentField) Next MsgBox("next line") Catch ex As Microsoft.VisualBasic.FileIO.MalformedLineException
MsgBox("Line " & ex.Message & "is not valid and will be skipped.") EndTry EndWhile EndUsing
Sweet. Now, you would want to use a DataTable and an OracleDataAdapter. The first step would be to download the ADO.NET provider for Oracle from the Oracle web site. Download and install ODP.NET and then add the appropriate reference to your project. You can now use the Oracle provider just as you would the providers built into the Framework, e.g. OleDb and SqlClient.
I would create an OracleDataAdapter. Using the appropriate query, you can call FillSchema on it to build the appropriate schema in a DataTable. You can then populate that DataTable with the data from the file. Once you're done, call Update on the adapter to insert the records into the database. You might like to take a look at this to get a feel for ADO.NET:
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.