| Subject |
Re: importing csv file |
| From |
Mustansir Ghor <mustan31@hotmail.com> |
| Date |
Wed, 30 Jun 2021 11:56:31 -0400 |
| Newsgroups |
dbase.getting-started |
Dear Mervyn Sir
Thank you.
This is going to help long way
Best Regards
Mustansir
Mervyn Bick Wrote:
> On 2021/06/30 10:39, Mustansir Ghor wrote:
> > Dear Gaetano
> >
> > I am sending csv file that need to be appended
> >
>
> My previous message crossed this one.
>
> A little example program is attached.
>
> Mervyn.
>
> if file('ghor_1.dbf')
> drop table ghor_1
> endif
>
> if not file('ghor_1.dbf')
> create table ghor_1 (location character(15),district character(15),;
> ward character(15),unit character(5),area int,demand_note date,;
> last_invoice_date date,next_invoice_date date,agreement_date date)
> endif
>
> //If you have an existing table delete or comment out the above.
>
> //The field names are not used in the code below so it doesn't
> //matter if you have used different field names
>
> //Edit the values for cTable and cCSV to suit.
>
> cTable = 'ghor_1'
> cCSV = 'ghor.csv'
> cDate = set('date') //save date format
> set date to american //dates in .csv are in American format
> set procedure to :duflp:stringex.cc
> q = new query()
> q.sql = "select * from "+cTable
> q.active = true
> f = new file()
> f.open(cCSV)
> cRead = f.gets(100000) // Skip record with field names
> do while not f.eof()
> cRead = f.gets(100000)
> aRecord = new stringex(cRead).breakstring(",",true)
> q.rowset.beginAppend()
> for n = 1 to aRecord.size
> if q.rowset.fields[n].type = 'DATE'
> q.rowset.fields[n].value = ctod(aRecord[n])
> else //all numeric and character field types can simply be saved
> q.rowset.fields[n].value = aRecord[n]
> endif
> next
> q.rowset.save()
> enddo
> f.close()
> q.active = false
> close procedure :duflp:stringex.cc
> msgbox('Done')
> set date to &cDate // set date format back to original
|
|