Switch to full style
You can find discussions, solutions and codes related to ASP.NET
Post a reply

Import text file with ASP.NET

Wed Nov 05, 2008 6:21 pm

HI...

I'm new in asp.net, I get a problem when import a file text file to
database sql server wtih asp.net, here the sample of the text file

Code:
0618888888 KURNIA SEMARANG 86 63360
0619999999 HIAPEE WAHIDIN 105 95664

i get a problem when split those records.

here is my script :
Code:
Dim strcontenttype FileUpload1.PostedFile.ContentType
Dim ms 
As New System.IO.StreamReader
(FileUpload1.PostedFile.InputStream)
Dim strResult As String ms.ReadToEnd()

Dim recStr() As String strResult.Split("vbcrlf")
Dim recItem As String ""
Dim nLoop As Integer 0
Dim arRec
(recStr.Length) As MyRecord



Dim nt 
As String
Dim nm 
As String
Dim kt 
As String
Dim id 
As String
Dim nom 
As Decimal

For nLoop 0 To recStr.Length 1
recItem 
recStr(nLoop)
If 
recItem.Length 106 Then
nt 
recItem.Substring(014)
nm recItem.Substring(1523)
kt recItem.Substring(2438)
id recItem.Substring(3953)
nom CType(recItem.Substring(54), Decimal)
Dim command As SqlCommand
Dim connection 
As New SqlConnection("Data
Source=xxx;Initial Catalog=xxxx;User ID=xxx; password=xxxx"
)
command connection.CreateCommand
command
.CommandText "INSERT INTO xxxx
(aaa,bbb,ccc,ddd,eeee) VALUES ('" 
recItem.Substring(014) & "','"
recItem.Substring(1523) & "','" recItem.Substring(2438)
"','" recItem.Substring(3953) & "','" CType(recItem.Substring
(54), Decimal) & "')"
connection.Open()
command.ExecuteNonQuery()
connection.Close()
End If
Next


Please help me how to read those record please:)



Post a reply
  Related Posts  to : Import text file with ASP.NET
 import XSD file in another     -  
 Create a text file     -  
 display the content of text file     -  
 Reading and Writing To text file     -  
 Search records from text file     -  
 Read Arabic text from file     -  
 uploading text file to java program     -  
 the text file i saved all in one line. How can i solve it?     -  
 Static Import     -  
 import Mysql database     -  

Topic Tags

ASP Files and I/O