Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Import file

Status
Not open for further replies.

beti

Programmer
Oct 6, 2002
26
0
0
US
Dear all,
I am newbie to Power Builder and have some problems with import file.
I need to import a file and save the data onto database. I wonder does it is neccessary to import the file onto datawindow first then save the data in the datawindow onto database? Can I directly save the data from the import file onto database without going through the datawindow?
any simple code showing how to do it?

Thanks millions
 
I frequently use datawindows with external data sources and fill them from tab-delimited text files. If that's what you are doing, there is no choice that I've found to get the data into a database other than to do the ImportFile and then loop through the datawindow rows and issue appropriate SQL or insert rows into a second datawindow that is built over the target table in the database. Unfortunately, external data source data windows do not allow use of ShareData, nor is there a way to "connect" this kind of datawindow to a database. External source dw's don't even seem to allow sorting, grouping etc like those based on a database table.

Hope this helps; if anyone out there knows of better ways I'd sure like to hear your suggestions.
 
there are different ways to do this things depending on different scenarios. I don't know what ur expecting to do ....

# If you just simply want to import from a file(txt without headers) then I think the database itself provide tools/menuoptions to import .

#But if ur importing data from a file only to a single table then u can do in PB by going to the database..open that particular table n import from the main menu of PB itself.

#But if you want to implement in an application then
you can do the same . If you want to import data for multiple tables from a single file then I think u have to use datawindow then save accordingly.

 
Beti,

Importing the file into the datawindow is more
graceful as it validates the data. If there are
no validations, you may just use the table painter
Edit Data and import the rows without using a dw.
All imported rows have a status flag of NewModified!
meaning an INSERT statement is generated for each
row. If there are any unique constraints and if
any inserted row already exists in the table, you
may get some errors.

---
PowerObject!
-----------------------------------------
PowerBuilder / PFC Developers' Group
 
Thank you for all of you! =)

 
Can anyone give me a sample code how to read a text delimited file and display on a datawindow?
I can't find anything on it.

Thanks
 
Follow up on my earlier post-

It IS possible to get an external dw to sort but not through the painter definition. You have to do the import and then set the sort order as shown in the code fragment below. This code came from the open event of the window that holds the dw control.

//filename.txt is a tab delimited text file formatted
//same as the datawindow columns in dw_report
string lsFileName = "filename.txt"
long llRes

//ImportFile has more parms that can be useful
//see PB Help for details.
//ImportString might be something to look at, too.

//capturing the result can be helpful in debug
llRes = dw_report.ImportFile( lsfilename )

//col1 is the name of a column in the dw. More
//complex sorts are possible; see PB Help
dw_report.SetSort( "col1 A")

//necessary to apply the sort criteria
dw_report.Sort()

Anyone have any ideas how group by could be implemented?
I'm still looking for a way to do that.


 
RGWith,

To create a group on an external dw, just use the menu: Rows->Create Group. On the Sort Group tab-page, drag the columns specified in the group-expression and make sure that they are just the column names. When you drag the columns, they get converted to expressions such as Count( col for group 1 ). Just double-click the dragged column and edit the expression to make it the name of the column in the Modify Expression dialog.

---
PowerObject!
-----------------------------------------
PowerBuilder / PFC Developers' Group
 
Follow up (2)
I agree with the above post about creating the group but I just found that in addition to the code I posted earlier it is necessary to include dw.GroupCalc() after the dw.Sort().
That is what makes the groups appear in the datawindow.
 
Thank you rgwith and powerobject! =)

 
Sorry is me again!
I encountered a problem when I tried to import a file into a datawindow.
I want to let user select the file to import..so I specify a Null string for the filename. But I keep getting a return value of 0. What have been wrong? I even tried to point to a specific file and I still get return of 0.

Here is my script:
string null_str
setNull(null_str)
int errormessage
if dw_importfile.importfile(null_str) > 0 then
messagebox("import", errormessage)
else
messagebox("import", errormessage)
end if


Please help! thanks
 
Does the file have any rows in it? Is the structure of file (# of columns/datatypes) the same as the dw which you are trying to import data into?

---
PowerObject!
-----------------------------------------
PowerBuilder / PFC Developers' Group
 
PowerObject,

Thanks for reminding me. I think I did not set up the #column and datatype correctly in the datawindow.

Thanks so much! =>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top