Board index » jbuilder » Why is my new row not being added?

Why is my new row not being added?


2004-06-16 02:21:06 AM
jbuilder2
I have a very strange problem. I am trying to add a new row to the database
using querydataset's addrow method and saving changes back to the database
using database.savechanges method.
No error is generated nor there is any exceptions but no data is added to
the database and my dataaware components can't see that new row either.
What could possibly be the probelm. I will paste a code snipet here
//q IS THE QUERYDATASET
DataRow dataRow1 = new DataRow(q);
int k = jComboBox2.getSelectedIndex() ;
dataRow1.setString("CODE" , v3.elementAt(k).toString() );
dataRow1.setString("EAP_ID" , eapid );
dataRow1.setDate("START_D",java.sql.Date.valueOf(datePicker1.getEditor().get
Text()) );
dataRow1.setDate("END_D",java.sql.Date.valueOf(datePicker2.getEditor().getTe
xt()) );
int i = jComboBox1.getSelectedIndex() ;
dataRow1.setString("SUPP_NAME" ,
jComboBox1.getSelectedItem().toString() );
dataRow1.setString("SUPP_ID" , v1.elementAt(i).toString() );
dataRow1.setDouble("TOTAL_HRS" , Double.parseDouble(
jTextField2.getText()) );
dataRow1.setString("LONGVAL" , jdbTextArea1.getText() );
dataRow1.setDouble("HPW" ,
Double.parseDouble(jTextField1.getText() ) );
dataRow1.setDouble("WEEKS" ,
Double.parseDouble(jTextField3.getText() ) );
dataRow1.setDouble("RATE" ,
Double.parseDouble(jTextField4.getText() ) );
dataRow1.setBoolean("APPROVED", approved);
if (approved == true)
dataRow1.setDate("APPR_DATE",
java.sql.Date.valueOf(datePicker3.getEditor().getText()));
dataRow1.setBoolean("INVOICED", invoice);
if (invoice == true) {
dataRow1.setDate("INV_DATE",
java.sql.Date.valueOf(datePicker4.getEditor().getText()));
dataRow1.setString("INV_NUM" , jTextField5.getText() );
}
dataRow1.setBoolean("CASH_REC", cash);
if (cash == true )
dataRow1.setDate("CASH_DATE",
java.sql.Date.valueOf(datePicker5.getEditor().getText()));
Database d = q.getDatabase() ;
q.addRow(dataRow1);
d.saveChanges(q);
 
 

Re:Why is my new row not being added?

"Ali" < XXXX@XXXXX.COM >wrote in message
Quote
I have a very strange problem. I am trying to add a new row to the
database
using querydataset's addrow method and saving changes back to the database
using database.savechanges method.
No error is generated nor there is any exceptions but no data is added to
the database and my dataaware components can't see that new row either.
What could possibly be the probelm. I will paste a code snipet here

I did not see where you have a unique RowID defined. You must have one to
resolve changes, or write your ownCustomResolver.
 

Re:Why is my new row not being added?

I had the rowid property set through designer before. Just to make sure i
also included it progmatically as follows:
q.setRowId("DETAIL_ID", true);
Still its not saving the changes to the database.
"Paul Nichols (TeamB)" < XXXX@XXXXX.COM >wrote in message
Quote

"Ali" < XXXX@XXXXX.COM >wrote in message
news:40cf3dff$ XXXX@XXXXX.COM ...
>I have a very strange problem. I am trying to add a new row to the
database
>using querydataset's addrow method and saving changes back to the
database
>using database.savechanges method.
>No error is generated nor there is any exceptions but no data is added
to
>the database and my dataaware components can't see that new row either.
>What could possibly be the probelm. I will paste a code snipet here
>
I did not see where you have a unique RowID defined. You must have one to
resolve changes, or write your ownCustomResolver.


 

{smallsort}

Re:Why is my new row not being added?

"Ali" < XXXX@XXXXX.COM >wrote in message
Quote
I had the rowid property set through designer before. Just to make sure i
also included it progmatically as follows:
q.setRowId("DETAIL_ID", true);

Still its not saving the changes to the database.

Are you sure have all of your user defined rows are mapped correctly to the
fields in the table? Did you change and test your sql statements AFTER you
added the additional DataRow?
 

Re:Why is my new row not being added?

Quote
Are you sure have all of your user defined rows are mapped correctly to
the
fields in the table?
Yes all of them are there and properly mapped to a table. Some of those
columns are set as invisible (visible-false) in the querydataset. I hope
that does not make any difference wehn i am adding a new row to the dataset.
Also there are 2 fields in that querydataset which are a resultant of an
inner join to another table. So lets say 7 fields are from table A and the
remaining 2 are from table B. I am trying to add a row with all the data for
table A. Since the query for the dataset is of join tye, refreshing the
dataset returns the new values for those perticular fields of table B.
Did you change and test your sql statements AFTER you
added the additional DataRow?
Yes I did. Still nothing
 

Re:Why is my new row not being added?

Borlands database components are very finniky.
After much divining of docs, and gnashing of teeth, I have (almost) gotten
all the pieces.
First, you need to set a PRIMARY KEY in your dabase table.
USE 'MyDataBase'
CREATE TABLE 'MyTable'
(
Key1 INT NOT NULL AUTOINCREMENT,
Key2 INT NOT NULL,
Data VARCHAR(25);
PRIMARY KEY (Key1, Key2)
)
public void example()
{
// Before you open your dataset, you must change the query resolver.
QueryResolver keyQueryResolver = new QueryResolver();
keyQueryResolver.setDatabase( myDatabase );
keyQueryResolver.setUpdateMode( UpdateMode.KEY_COLUMNS );
// now set up the query and set up the query resolver to it.
// (according to the docs, you can reuse the same query resolver with any
table on the same database)
QueryDataSet q = new QueryDataSet(...); // you fill in the details ...
q.setResolver( keyQueryResolver );
q.setMetaDataUpdate(MetaDataUpdate.NONE);
q.setTableName("MyTable");
// set up the rowid's column(s) for the keys
Column firstkeycol = new Column("Key1", "Key1", Variant.INT );
firstkeycol .setRowId(true);
firstkeycol .setAutoIncrement(true);
firstkeycol .setTableName(("MyTable");
firstkeycol .setPersist(true);
// repeat for next key
Column secondkeycol = new Column("Key2", "Key2", Variant.INT );
secondkeycol .setRowId(true);
secondkeycol .setTableName(("MyTable");
secondkeycol .setPersist(true);
// assign the columns to the query
// and open the query
q.setColumns( new Column[] { firstkeycol, secondkeycol } );
q.executeQuery();
// add the row, post it, and save (i'm not sure post is necessary, but it
doesn't seem to hurt)
q.addRow(dataRow1);
q.post();
q.SaveChanges();
}
There's probably more to it than that, which Borland is not to explicit in
describing.
regards,
Dar7yl (the 7 is silent)
"Ali" < XXXX@XXXXX.COM >wrote in message
Quote
I have a very strange problem. I am trying to add a new row to the
database
using querydataset's addrow method and saving changes back to the database
using database.savechanges method.
No error is generated nor there is any exceptions but no data is added to
the database and my dataaware components can't see that new row either.
What could possibly be the probelm. I will paste a code snipet here

//q IS THE QUERYDATASET


DataRow dataRow1 = new DataRow(q);
int k = jComboBox2.getSelectedIndex() ;
dataRow1.setString("CODE" , v3.elementAt(k).toString() );

dataRow1.setString("EAP_ID" , eapid );


dataRow1.setDate("START_D",java.sql.Date.valueOf(datePicker1.getEditor().get
Text()) );


dataRow1.setDate("END_D",java.sql.Date.valueOf(datePicker2.getEditor().getTe
xt()) );

int i = jComboBox1.getSelectedIndex() ;
dataRow1.setString("SUPP_NAME" ,
jComboBox1.getSelectedItem().toString() );
dataRow1.setString("SUPP_ID" , v1.elementAt(i).toString() );
dataRow1.setDouble("TOTAL_HRS" , Double.parseDouble(
jTextField2.getText()) );
dataRow1.setString("LONGVAL" , jdbTextArea1.getText() );


dataRow1.setDouble("HPW" ,
Double.parseDouble(jTextField1.getText() ) );
dataRow1.setDouble("WEEKS" ,
Double.parseDouble(jTextField3.getText() ) );
dataRow1.setDouble("RATE" ,
Double.parseDouble(jTextField4.getText() ) );

dataRow1.setBoolean("APPROVED", approved);
if (approved == true)
dataRow1.setDate("APPR_DATE",

java.sql.Date.valueOf(datePicker3.getEditor().getText()));

dataRow1.setBoolean("INVOICED", invoice);
if (invoice == true) {
dataRow1.setDate("INV_DATE",

java.sql.Date.valueOf(datePicker4.getEditor().getText()));
dataRow1.setString("INV_NUM" , jTextField5.getText() );

}

dataRow1.setBoolean("CASH_REC", cash);

if (cash == true )
dataRow1.setDate("CASH_DATE",

java.sql.Date.valueOf(datePicker5.getEditor().getText()));

Database d = q.getDatabase() ;
q.addRow(dataRow1);
d.saveChanges(q);



 

Re:Why is my new row not being added?

Thank you so much all of you. I, with ur help was able to atleast add a row to the database. What it did was that it for some unknown reason destroyed my master-detail relationship with another table. ( mind u this table i am adding to is a detail)
Anyone here who knows where to go ??
I am a big fan of borland and i am sure its as powerful as anything but lack of articals or tutorials make its components (DataExpress for instance) very hard to grasp.
Regards
 

Re:Why is my new row not being added?

"Ali" < XXXX@XXXXX.COM >wrote in message
Quote

Thank you so much all of you. I, with ur help was able to atleast add a
row to the database. What it did was that it for some unknown reason
destroyed my master-detail relationship with another table. ( mind u this
table i am adding to is a detail)
yer welcome. sorry I can't help you with your master/apprentice issues.
(maybe a whipping is in order:)
Quote

Anyone here who knows where to go ??
Not I. I've already perused the meagre Borland docs, and I'm still having
problems everytime I try to access a database.
Quote

I am a big fan of borland and i am sure its as powerful as anything but
lack of articals or tutorials make its components (DataExpress for instance)
very hard to grasp.
It's not only the lack of docs, but the whole concept is flawed. There
isn't a single conceptual level involved, but the designers seem to bounce
up and down between high-level and low-level concepts. There isn't one place
to look for a detailed solution either.
regards,
Dar7yl (the 7 is silent)
 

Re:Why is my new row not being added?

Quote
It's not only the lack of docs, but the whole concept is flawed.
I agree with you. I used to program with MFC and I have to
admit there was atleast a standard being maintained by the
developers and obviously that huge MSDN always comes in handy.
I think borland staff should recognise this fact that
DataExpress or perhaps any other components are not just any
other classes. Its probably a semi-complete framework which in
my opinion, as you have mentioned as well, a proper logical
layer and a lot of documentation for people like you and I to
develop more efficently. ( just my two cents!)
I stress on documentation a lot just because its very
important. Check out IBM's developers website and you will feel
the difference.
 

Re:Why is my new row not being added?

In <40cfc12c$ XXXX@XXXXX.COM >Ali wrote:
Quote
I think borland staff should recognise this fact that
DataExpress or perhaps any other components are not just any
other classes. Its probably a semi-complete framework which in
my opinion, as you have mentioned as well, a proper logical
layer and a lot of documentation for people like you and I to
develop more efficently. ( just my two cents!)
go to the links below for more info on DataExpress..
--
=============================================
TeamB are volunteer helpers. Please DO NOT REPLY VIA EMAIL!
Post all questions and replies to this newsgroup ONLY
For papers on DataExpress, Applets, JSP, and Web Development go to:
www.microps.com/mps/papers.html
====================================================
 

Re:Why is my new row not being added?

In < XXXX@XXXXX.COM >Ali wrote:
Quote
Also there are 2 fields in that querydataset which are a
resultant of an inner join to another table.
Ouch.. and you DID flag those fields as not "resolvable"...yes???
<G>
Actually, I have been using DX for quite a while now, with minimal
problems, and I have come up with some simple "rules" to insure what you
do always works..
1) Don't event think about resolving to a joined dataset.
a) you can get this to work but is it worth the pain...??
2) ALWAYS set the rowID's after executing the query..
3) ALWAYS set the table name at the same time.
a) Drivers don't always follow the specs.. this insures that it
does not matter..
4) Don't use "addRow", do an qds.insertRow() then set your fields and
post()
a) addRow is clunky IMO.. if there is a problem reported here it
is always because the user was trying to use addRow.. Nuff said...
5) Make sure you always post() after each edit.
a) People forget this all the time..<sigh>
6) Use the database.saveChanges(...) version not the qds.saveChanges()
version.
a) allows you transaction control, a good habit to develope...
John..
--
=============================================
TeamB are volunteer helpers. Please DO NOT REPLY VIA EMAIL!
Post all questions and replies to this newsgroup ONLY
For papers on DataExpress, Applets, JSP, and Web Development go to:
www.microps.com/mps/papers.html
====================================================