March 21st, 2014, 09:29 AM
Join Date: Mar 2014
Time spent in forums: 41 m 6 sec
Reputation Power: 0
Getting first Letter of Strings and insert them in Access
I'm new to this forum.
I am trying to get the first letter from two strings (Firstname and Lastname) and insert them into an access database.
Now the problem is not to get the first letters but to insert them into the database while inserting a new row as I have a field in the database named "User" in which i try to insert the first letters plus the automated ID from another field (STU_ID).. The thing is that the autogenerated Id in access is just created after
i inserted the new row so i cant get the ID before... But when i try to get it afterwards the current row is the first in the recordset and i get the first letters of the last record plus the ID from the first record saved into the first records User field...
Any idea how i could achieve this (if someone understand)?
here my current code:
String first = txtFName.getText( );
String last = txtLName.getText( );
int eng = Integer.parseInt(txtEng.getText());
int mat = Integer.parseInt(txtMat.getText());
int phy = Integer.parseInt(txtPhy.getText());
int geo = Integer.parseInt(txtGeo.getText());
String name = lblName.getText();
Date newdate = new Date();
java.sql.Date sqldate = new java.sql.Date(newdate.getTime());
String firstLetterFN = first.substring(0, 1);
String firstLetterLN = last.substring(0, 1);
jLabel8.setText(firstLetterFN + FirstLetterLN);
rs.updateString( "FName", first );
rs.updateString( "lName", last );
rs.updateInt( "English", eng );
rs.updateInt( "Mathematics", mat);
rs.updateInt( "Physics", phy);
rs.updateInt( "Geography", geo);
rs.updateDate( "Last Modified", sqldate);
rs.updateString( "Modified by", name);
int id2 = rs.getInt("STU_ID");
String user = firstLetterFN + firstLetterLN + "_" + "S" + id2;
Thanks in advance..
//Edit: Ok I tried a few things and now I got it.
I just changed the rs.moveToCurrentRow() to rs.last() and its working fine. Thansk anyway
Last edited by Nyra : March 21st, 2014 at 09:52 AM.
Reason: Found answer myself