Click here to Skip to main content
12,500,915 members (54,359 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: VB VB.NET
| Sr.No | Membership No | Name | Addresss | Occupation |
|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Account |
|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| | 35957 | SHAH HEMANGINI KANAIYALAL NATVARLAL |SHROFF STREET,, KILLA PARDI, DIST.VALSAD, Pardi, Pin Cd : 396125 |
| 1 | 35959 | SARSIWALA SAKINABEN ASGARALI ABDULHUSEIN |OPP.HIGHPOWER SODA FACTORY,, DUNGRI FALIA,DAMNI ZAPA,, KILLA PARDI.DIST.VAL |
| 2 | 36022 | PATEL BHARTIBEN BABUBHAI KHANDUBHAI |B/H BALMANDIR,, KANSARWAD,, KILLA PARDI., Pardi, Pin Cd : 396125 |
| 3 | 36023 | PATEL ASHISHKUMAR BABUBHAI KHANDUBHAI |B/H BALMANDIR,, KANSARWAD,, KILLA PARDI., Pardi, Pin Cd : 396125 |
| 4 | 36025 | SHAIKH HALIMABIBI UMARBHAI MOHMEDBHAI |OPP.JALARAM KHAMAN HOUSE,, CHIVAL ROAD,, KILLA PARDI.DIST.VALSAD, Pardi, Pi |
| 5 | 36072 | LAD PUSHPABEN VINODBHAI BHANABHAI |KUMBHARWAD,, VALSADI ZAPA,, KILLA PARDI,DIST.VALSAD, Pardi, Pin Cd : 396125 |
| 7 | 36076 | KOTHARI PANNABEN JANAKBHAI ISHVARLAL |VANIAWAD,, KILLA PARDI, DIST.VALSAD, Pardi, Pin Cd : 396125 |
| 8 | 36080 | PATEL DHARMESH BHAGUBHAI KANJIBHAI |NEAR RATAN RICE MILL,, DAMNI ZAPA,, KILLA PARDI., Pardi, Pin Cd : 396125 |
| 9 | 36081 | MAPARA BANKIMKUMAR SUNDARLAL HARJIVANDAS |BALAKHADI,, STATION ROAD,, KILLA PARDI, Pardi, Pin Cd : 396125 |
| 10 | 36084 | LAD JAMNABEN DAHYABHAI BHAGWANJI |KUMBHARWAD,, VALSADI ZAPA,, KILLA PARDI, Pardi, Pin Cd : 396125 |
| 11 | 36085 | PRAJAPATI RAKESHKUMAR THAKORBHAI KESHAVB |B/H NUTAN NAGAR,, KAKABAVANI WADI,, KILLA PARDI., Pardi, Pin Cd : 396125 |
| 12 | 36086 | PATEL BHANUBEN THAKORBHAI RAGHABHAI |B/H MOHAN DAYAL HOSPITAL,, DAMNI ZAPA,, KILLA PARDI., Pardi, Pin Cd : 39612 |
| 13 | 36089 | PATEL PRAFULBHAI BUDHABHAI CHHANABHAI |DANTI FALIA,, CHIVAL ROAD,, KILLA PARDI, Pardi, Pin Cd : 396125 |
| 14 | 36093 | JOSHI KANAKBHAI MANUBHAI |ISHVARPARK,, BRAHMIN FALIA,, KILLA PARDI, Pardi, Pin Cd : 396125 |
| 15 | 36095 | DESAI MEGHABEN BHAVINBHAI ISHVARBHAI |101-ANAND APARTMENT,, OPP.D.C.O.SCHOOL,BALAKHADI,, KILLA PARDI., Pardi, Pin |
| 16 | 36204 | PATEL MANIBEN CHIMANLAL BABUBHAI. |DEVKA FALIA,, STATION ROAD,CHAR RASTA,, KILLA PARDI.DIST.VALSAD., Pardi, Pi |
| 17 | 36211 | MISTRY RANJANABEN ASHOKBHAI BHAGWANJI |SUKHLAV ROAD,JAKAT NAKA,, DAMNI ZAMPA,, KILLA PARDI., Pardi, Pin Cd : 39612 |
| 18 | 36295 | PRAJAPATI JAYESH CHHAGANBHAI RANCHHODBHA |KUMBHARWAD,, VALSADI ZAPA,, KILLA PARDI.DIST.VALSAD, Pardi, Pin Cd : 396125 |
| 19 | 36296 | KAHAR NARMADABEN GOVANBHAI BHAGUBHAI |KAHARWAD,, DAMNI ZAPA., KILLA PARDI.DIST.VALSAD, Pardi, Pin Cd : 396125 |
| 20 | 36328 | BHARATIA GIRISHCHANDRA KANTILAL RANCHHOD |"ANAND MANGAL",SAMIR HSG.SOC.LTD, NEAR SWATI COLONY,N.H.NO:8,, KILLA PARDI. |


For this text file I want to store SRNO,MembershipNo,Name,Address values in database.How to pick all these values individually and insert in database?
Help me with this.
Posted 22-Nov-12 21:01pm
Comments
__TR__ 23-Nov-12 3:17am
   
Use StreamReader.ReadLine Method[^] to read each line from the file and then use Split[^] method to get each column value. In your file each column is seperated by a "|", so use that character to split your line.
Rachna0309 23-Nov-12 3:25am
   
That even I thought of but how to read lines that contain SRNO,Membershipno etc...Which word I should find,after which I can get Srno etc.And also when I should stop reading lines because this file contains many other details in between and then again SRNO,membershipno,name,address values starts.

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

use this code...
Dim StrAreaCode As New List(Of String) 'collect area-codes

       Dim objStreamReader As New IO.StreamReader("E:\Rachna\ELECTION 2009-SHAREHOLDERS AREAWISE.txt")
       Dim strLine = objStreamReader.ReadLine
 
       Dim ReadGridFlag = -1
 
       Do While Not strLine Is Nothing
           If strLine.Trim.ToUpper.StartsWith("Area Code :".ToUpper) Then
               strLine.Trim()
               StrAreaCode.Add(strLine.Split(" :")(1)) 'ADD AreaCode in list
           End If
           strLine = objStreamReader.ReadLine
 
           If strLine.Trim.ToUpper.StartsWith("| Sr.No".ToUpper) Then
               ReadGridFlag = 0
           ElseIf ReadGridFlag = 1 Then
            Dim c = strLine.Split("|")
                Dim SrNo = c(1).Trim
                Dim memberNo = c(2).Trim
                Dim name = c(3).Trim
                Dim address = c(4).Trim
                
                Dim Query = "Insert into tbl (srno,memberno,name,address) values('" & SrNo & "','" & memberNo & "','" & name & "','" & address & "')"
               'write code to execute query ...

           ElseIf strLine.Trim.ToUpper.StartsWith("|--".ToUpper) And ReadGridFlag = 0 Then
               ReadGridFlag = 1
           End If
       Loop
       objStreamReader.Close()
Happy Coding!
:)
  Permalink  
Comments
Rachna0309 23-Nov-12 3:47am
   
This code will split the below line:
| Sr.No | Membership No | Name | Addresss

I want to split this line:
| 1 | 35959 | SARSIWALA SAKINABEN ASGARALI ABDULHUSEIN |OPP.HIGHPOWER SODA FACTORY,, DUNGRI FALIA,DAMNI ZAPA,, KILLA PARDI.DIST.VAL |
and store these splitted values in database
Aarti Meswania 23-Nov-12 3:56am
   
this will do that task check properly
i have split line and take all values in variables
srno, memberno,name, address (see underlined portion)

debug it, you will get values in variables
Rachna0309 23-Nov-12 4:27am
   
ok thanx..

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160919.1 | Last Updated 23 Nov 2012
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100