cmd.CommandText = "UPDATE tblSOF SET Tuition ='" & txtTuition.Text & "', Registration ='" & txtReg.Text & "', Athletic ='" & txtAfee.Text & "', Guidance ='" & txtGuidance.Text & "', LearningMatAndKit ='" & txtMat.Text & "', ScienceLab ='" & txtScience.Text & "', CompLab ='" & txtComplab.Text & "', Library ='" & txtLib.Text & "', MedicalDental ='" & txtMed.Text & "', SHA ='" & txtSha.Text & "', SchoolPublication ='" & txtSpub.Text & "', IDFee ='" & txtIDfee.Text & "', SWF ='" & txtSWF.Text & "', TestPaper ='" & txtTpaper.Text & "', DECsFee ='" & txtDecs.Text & "', ActivityFee ='" & txtAfee.Text & "', CSATPACT ='" & txtCsat.Text & "', DevelopmentFee ='" & txtDfee.Text & "', TechnologyFee ='" & txtTfee.Text & "', JournalSRI ='" & txtJournal.Text & "', ComputerFee ='" & txtCompfee.Text & "', TeachersAide ='" & txtTaide.Text & "', Aircon ='" & txtAircon.Text & "', WholeYear ='" & txtWyear.Text & "', 2ndChild ='" & txt2nd.Text & "', & 3rdChild ='" & txt3rd.Text & "', 4thChild ='" & txt4th.Text & "', 5thChild ='" & txt5th.Text & "' WHERE YearGrade=" & dgvLevel.CurrentRow.Cells(0).Value
Update syntax error
Page 1 of 18 Replies - 321 Views - Last Post: 25 February 2012 - 01:57 AM
#1
Update syntax error
Posted 24 February 2012 - 11:59 PM
Is there something wrong with my code? I've followed my update code from my previous project. By the way I use text as datatype on my database but the inputs were numbers(used for payment/fees). I tried to remove the single quotes but it is still no good. What do you think guys? Thanks in advance if someone could help.
Replies To: Update syntax error
#2
Re: Update syntax error
Posted 25 February 2012 - 12:37 AM
I think you've missed the ending double quotes.
YearGrade='" & dgvLevel.CurrentRow.Cells(0).Value "' "
This post has been edited by nK0de: 25 February 2012 - 12:38 AM
#3
Re: Update syntax error
Posted 25 February 2012 - 01:11 AM
Tried your resolve sir nK0de but no luck. There was an error in your code so I tried to use this one instead.
This code is still not working though.
This code is still not working though.
YearGrade='" & dgvLevel.CurrentRow.Cells(0).Value & "'"
This post has been edited by EtienneBordeaux: 25 February 2012 - 01:19 AM
#4
Re: Update syntax error
Posted 25 February 2012 - 01:31 AM
my bad, I forgot the ampersand. sorry.
hmm...what's the error you're getting?
hmm...what's the error you're getting?
#5
Re: Update syntax error
Posted 25 February 2012 - 01:34 AM
syntax error in update statement
#6
Re: Update syntax error
Posted 25 February 2012 - 01:52 AM
YearGrade='" & dgvLevel.CurrentRow.Cells(0).Value & "'"
try change to like
YearGrade Like '" & dgvLevel.CurrentRow.Cells(0).Value & "%'"
#7
Re: Update syntax error
Posted 25 February 2012 - 01:56 AM
this right here. An wild ampersand in the front.
cmd.CommandText = "UPDATE tblSOF SET Tuition ='" & txtTuition.Text & "', Registration ='" & txtReg.Text & "', Athletic ='" & txtAfee.Text & "', Guidance ='" & txtGuidance.Text & "', LearningMatAndKit ='" & txtMat.Text & "', ScienceLab ='" & txtScience.Text & "', CompLab ='" & txtComplab.Text & "', Library ='" & txtLib.Text & "', MedicalDental ='" & txtMed.Text & "', SHA ='" & txtSha.Text & "', SchoolPublication ='" & txtSpub.Text & "', IDFee ='" & txtIDfee.Text & "', SWF ='" & txtSWF.Text & "', TestPaper ='" & txtTpaper.Text & "', DECsFee ='" & txtDecs.Text & "', ActivityFee ='" & txtAfee.Text & "', CSATPACT ='" & txtCsat.Text & "', DevelopmentFee ='" & txtDfee.Text & "', TechnologyFee ='" & txtTfee.Text & "', JournalSRI ='" & txtJournal.Text & "', ComputerFee ='" & txtCompfee.Text & "', TeachersAide ='" & txtTaide.Text & "', Aircon ='" & txtAircon.Text & "', WholeYear ='" & txtWyear.Text & "', 2ndChild ='" & txt2nd.Text & "', & 3rdChild ='" & txt3rd.Text & "', 4thChild ='" & txt4th.Text & "', 5thChild ='" & txt5th.Text & "' WHERE YearGrade='" & dgvLevel.CurrentRow.Cells(0).Value & "' "
btw I suggest you use the datatype money for currency values in SQL Server. And other appropriate datatypes for numeric values. Using Text for everything is not right. You may run into problems in your program later on.
and damdimdum,
try change to like
you normally don't use the LIKE operator in updating for it can cause hazardous results. It'll update not only the exact record we want to update but every record which matches the condition!
& 3rdChild ='" & txt3rd.Text & "'
cmd.CommandText = "UPDATE tblSOF SET Tuition ='" & txtTuition.Text & "', Registration ='" & txtReg.Text & "', Athletic ='" & txtAfee.Text & "', Guidance ='" & txtGuidance.Text & "', LearningMatAndKit ='" & txtMat.Text & "', ScienceLab ='" & txtScience.Text & "', CompLab ='" & txtComplab.Text & "', Library ='" & txtLib.Text & "', MedicalDental ='" & txtMed.Text & "', SHA ='" & txtSha.Text & "', SchoolPublication ='" & txtSpub.Text & "', IDFee ='" & txtIDfee.Text & "', SWF ='" & txtSWF.Text & "', TestPaper ='" & txtTpaper.Text & "', DECsFee ='" & txtDecs.Text & "', ActivityFee ='" & txtAfee.Text & "', CSATPACT ='" & txtCsat.Text & "', DevelopmentFee ='" & txtDfee.Text & "', TechnologyFee ='" & txtTfee.Text & "', JournalSRI ='" & txtJournal.Text & "', ComputerFee ='" & txtCompfee.Text & "', TeachersAide ='" & txtTaide.Text & "', Aircon ='" & txtAircon.Text & "', WholeYear ='" & txtWyear.Text & "', 2ndChild ='" & txt2nd.Text & "', & 3rdChild ='" & txt3rd.Text & "', 4thChild ='" & txt4th.Text & "', 5thChild ='" & txt5th.Text & "' WHERE YearGrade='" & dgvLevel.CurrentRow.Cells(0).Value & "' "
btw I suggest you use the datatype money for currency values in SQL Server. And other appropriate datatypes for numeric values. Using Text for everything is not right. You may run into problems in your program later on.
and damdimdum,
damdimdum, on 25 February 2012 - 02:22 PM, said:
YearGrade='" & dgvLevel.CurrentRow.Cells(0).Value & "'"
try change to like
YearGrade Like '" & dgvLevel.CurrentRow.Cells(0).Value & "%'"
you normally don't use the LIKE operator in updating for it can cause hazardous results. It'll update not only the exact record we want to update but every record which matches the condition!
This post has been edited by nK0de: 25 February 2012 - 02:07 AM
#8
Re: Update syntax error
Posted 25 February 2012 - 01:57 AM
Thanks sir nK0de. That saved my ass. Cheers!
#9
Re: Update syntax error
Posted 25 February 2012 - 01:57 AM
Always the sql error messages say something like: "Syntax error near..." or so. Also please use parameterized query, with a lot of is benefits, it is also easy to debug and readable. This will help you easily see the error.
But again you have a debug capability in your IDE, use it. Put a break before the query and then during execution check what value is contained in CommandText, and look if anything is missing
But again you have a debug capability in your IDE, use it. Put a break before the query and then during execution check what value is contained in CommandText, and look if anything is missing
This post has been edited by smohd: 25 February 2012 - 02:00 AM
Page 1 of 1
|
|

New Topic/Question
Reply




MultiQuote






|