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