Click here to Skip to main content
15,884,099 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
I have a mistake in my project it shows the error like Incorrecr syntax neare ','. on updating my query

(" update payment set BATCHCODE=" + textBox2.Text + ", BATCHMEMBERS=" + comboBox6.Text + ", BATCHNAME='" + textBox10.Text + "', COURSE='" + comboBox5.Text + "', BRANCH='" + comboBox4.Text + "', COLLEGE='" + textBox8.Text + "', TITLE='" + textBox3.Text + "', TECHNOLOGY='" + comboBox2.Text + "', TYPE='" + comboBox1.Text + "',PROJECTSTATUS='" + comboBox3.Text + "',DELIVERYDATE='" + textBox9.Text + "', PROJECTCOST=" + textBox4.Text + ", PAIDAMOUNT=" + textBox12.Text + ",PAYMENT=" + textBox6.Text + ", BALANCE=" + textBox7.Text + " WHERE REGNO=" + textBox1.Text + "");

this is my code for updating when i add other field with payment the fields where updating, but when i enter other fields without payment it does'nt updating . please give sajections
Posted
Updated 31-Oct-10 21:24pm
v2
Comments
Hiren solanki 1-Nov-10 3:26am    
improved code readability.

SQL
(" update payment set BATCHCODE=" + textBox2.Text + ", BATCHMEMBERS=" + comboBox6.Text + ", BATCHNAME='" + textBox10.Text + "', COURSE='" + comboBox5.Text + "', BRANCH='" + comboBox4.Text + "', COLLEGE='" + textBox8.Text + "', TITLE='" + textBox3.Text + "', TECHNOLOGY='" + comboBox2.Text + "', [TYPE]='" + comboBox1.Text + "',PROJECTSTATUS='" + comboBox3.Text + "',DELIVERYDATE='" + textBox9.Text + "', PROJECTCOST=" + textBox4.Text + ", PAIDAMOUNT=" + textBox12.Text + ",PAYMENT=" + textBox6.Text + ", BALANCE=" + textBox7.Text + " WHERE REGNO=" + textBox1.Text + "");



I mark my changes as a bold

also make sure that BATCHCODE , BATCHMEMBERS are not a string data type (i mean nvarchar,varchar etc....)
 
Share this answer
 
Please make sure that this Dynamic SQL have values to set in the fields.
e.g. it should not look like as follows
update payment set BATCHCODE=, BATCHMEMBERS=, ..... 


there must be some values or null to assign in the columns for a update statement.
 
Share this answer
 
Comments
RDBurmon 1-Nov-10 8:15am    
I think CP , if wstar make sure that BATCHCODE , BATCHMEMBERS are not a string data type (i mean nvarchar,varchar etc....)
If it is a string data type the he must use BATCHCODE='" + textBox2.Text + "'.........
cp.soni 4-Nov-10 10:38am    
Yes, that is correct, but it could be possible that nothing is being passed from the controls which He should make sure.
maybe you need to verify your query in sql :
<pre lang="sql">update payment set
 BATCHCODE="'" + textBox2.Text + "'",
 BATCHMEMBERS="'" + comboBox6.Text + "'",
  BATCHNAME="'" + textBox10.Text + "'",
  COURSE="'" + comboBox5.Text + "'",
  BRANCH="'" + comboBox4.Text + "'",
  COLLEGE="'" + textBox8.Text + "'",
  TITLE="'" + textBox3.Text + "'",
  TECHNOLOGY="'" + comboBox2.Text + "'",
  [TYPE]= "'" + comboBox1.Text + "'",
  PROJECTSTATUS="'" + comboBox3.Text +"'",
  DELIVERYDATE="'" + textBox9.Text + "'",
  PROJECTCOST="'" + textBox4.Text + "'",
  PAIDAMOUNT="'" + textBox12.Text + "'",
  PAYMENT="'" + textBox6.Text + "'",
  BALANCE="'" + textBox7.Text + "'"
   WHERE REGNO="" + textBox1.Text + """

 
Share this answer
 
Comments
fjdiewornncalwe 3-Nov-10 15:03pm    
I like this one. The key is that if you surround ALL values with the single quotes, the sql parser will be able to handle them. It will automagically convert numerical values in the query to the appropriate underlying data type.
I can not find any mistake in UPDATE method, You just make sure that your any of TextBox or ComboBox value doesn't containing "," char.

My advise would be to have parameterized query update rather then attaching value inline.

See THIS[^] For more detail.

Please vote and Accept Answer if it Helped.
 
Share this answer
 
Comments
TweakBird 4-Nov-10 2:19am    
Mr Solanki,

i got error like this for your posted link. see the error message below.

HTTP Error 404.0 - Not Found
The resource you are looking for has been removed, had its name changed, or is temporarily unavailable.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900