You're missing the ' before the comma in this line:
sql += "'" + txtPostCode.getText()+ ", ";
Sometimes it just needs a new pair of eyes:)
hericles
Veteran Poster
1,065 posts since Nov 2007
Reputation Points: 156
Solved Threads: 228
Skill Endorsements: 10
There could be any number of problems, but the most likely is that you have not listed the column names that you expect to populate with the data listed in the VALUES clause. Generally speaking, it is good procedure to explicitly list the column names like so (and these names are fictitious...just for example's sake):
sql = "INSERT INTO empDetail ";
sql += "(empName, empAddress, empSuburb, empPostCode, empDOB, empPhone, empWorkExt, empMobile, empEMail) ";
sql += "VALUES('" + txtName.getText() + "', ";
sql += "'" + txtAddress.getText() + "', ";
sql += "'" + txtSuburb.getText() + "', ";
sql += "'" + txtPostCode.getText() + ", ";
sql += "'" + txtDOB.getText() + "', ";
sql += "'" + txtPhone.getText() + "', ";
sql += "'" + txtWorkExt.getText() + "', ";
sql += "'" + txtMobile.getText() + "', ";
sql += "'" + txtEmail.getText() + "')";
Let's say for instance that the table has an identity column "empID". If you don't explicitly list the column names, the INSERT statement will assume you mean for your first value to go into that column.
There could also be mismatched datatypes, but we'll ignore that for now. Or, heaven forbid, you get your columns in a different order than your VALUEs.
As a final word of advice, whenever you get odd errors you may want to just print the value of your variable "sql" and paste in an SSMS query window and see if it actually works. Sometimes when you strip away all the dynamic construction code and see what's actually being executed, the error will jump out at you.
Hope this helps! Good luck!
BitBlt
Practically a Posting Shark
894 posts since Feb 2011
Reputation Points: 482
Solved Threads: 148
Skill Endorsements: 14
Question Answered as of 1 Year Ago by
hericles
and
BitBlt