Total members 10249 | Gratitudes |It is currently Thu May 17, 2012 7:31 am Login / Join Codemiles


All times are UTC [ DST ]




Post new topic Reply to topic  Quick reply  [ 1 post ] 
Author Question
 Question subject: Import text file with ASP.NET
PostPosted: Wed Nov 05, 2008 6:21 pm 
Offline
Proficient
User avatar

Joined: Sun Oct 19, 2008 3:47 pm
Posts: 281
Has thanked: 0 time
Have thanks: 1 time

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

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(0, 14)
nm = recItem.Substring(15, 23)
kt = recItem.Substring(24, 38)
id = recItem.Substring(39, 53)
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(0, 14) & "','"
& recItem.Substring(15, 23) & "','" & recItem.Substring(24, 38)
& "','" & recItem.Substring(39, 53) & "','" & CType(recItem.Substring
(54), Decimal) & "')"
connection.Open()
command.ExecuteNonQuery()
connection.Close()
End If
Next


Please help me how to read those record please:)


TOP
 Profile Send private message  
Reply with quote  
Post new topic Reply to topic Quick reply  [ 1 post ] 
Quick reply


  

 Similar topics
 Image Insert in Excel File Using POI
 ASP file structure
 Search records from text file
 error closing file matlab save
 How to download any file in jsp.
 text Indent value to table
 Control font size of sub and sup text
 Change the text indent in the paragraph
 set text align to justify
 Add dashed border to text div

All times are UTC [ DST ]


Users browsing similar posts

Users browsing this forum: No registered users and 1 guest



Jump to:  
Previous Question | Next Question 




Home
General Talks
Finished Projects
Code Library
Games
Tutorials

Java
C/C++
C-sharp
php
Script
JSP/Servlets
Ajax
ASP/ASP.net
Google SEO
Database
Communications
Phpbb3 styles
Photoshop tutorials
Flash tutorials
Find a job






Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team