Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#
Database Design structure as follows;
 
Course Code text
Course Duration text
Hours text
 

Design as follows in run mode
Cmn_Minor_Code textbox1
Course_Duration textbox2
Allocated_Hours textbox3
 
i am inserting the above data in the database. it is working fine, no problem.
 

I am updating the course Duration and Allocated_Hours in the database using update query.
 
Update query as follows;
 
sql = "Update Tb_SCH_Faculty_Details set [Course_Duration,Allocated_Hours] = '" + textbox2.Text + "','" + textbox3 .Text + "' where Cmn_Minor_Code = '" + txt_coursecode.Text + "'";
 
when i run the above code shows error as follows
 
Syntax error in update statment.
 
what is the problem in my update query,
please help me.
 
Regards & Thanks,
Narasiman P
Posted 20-Feb-13 21:09pm
Comments
Surendra0x2 at 21-Feb-13 3:27am
   
sql = "Update Tb_SCH_Faculty_Details set [Course_Duration,Allocated_Hours] = '" + textbox2.Text + "','" + textbox3 .Text + "' where Cmn_Minor_Code = '" + txt_coursecode.Text + "'";
 
You Used Square Bracket here ?
why
if u want to update Multiple Columns then
simply
 
Update Tb_SCH_Faculty_Details set Course_Duration='" + textbox2.Text + "',Allocated_Hours='" + textbox3 .Text + "' where Cmn_Minor_Code = '" + txt_coursecode.Text + "'";

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Change your query to:
sql = "Update Tb_SCH_Faculty_Details set Course_Duration= '" + textbox2.Text + 
"',Allocated_Hours = '" + textbox3 .Text + "' where Cmn_Minor_Code = '" + txt_coursecode.Text + "'";
which will cure your immediate problem, but please, don't do it like that! Do not concatenate strings to build a SQL command. It leaves you wide open to accidental or deliberate SQL Injection attack which can destroy your entire database. Use Parametrized queries instead.
  Permalink  
Comments
Member 8054539 at 21-Feb-13 4:29am
   
i tried your query, when i update the course duration and allocated hourse and click the update button error shows as follows;
 
No value given for one or more required parametres.
OriginalGriff at 21-Feb-13 4:33am
   
Did you convert it to a parametrised query?
Copy and paste your code!
Hrushikesh_phapale at 21-Feb-13 5:21am
   
try to use parameterise query to update the records.

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

  Print Answers RSS
0 OriginalGriff 310
1 Sergey Alexandrovich Kryukov 201
2 PhilLenoir 164
3 Magic Wonder 162
4 Richard MacCutchan 160
0 Sergey Alexandrovich Kryukov 6,140
1 OriginalGriff 5,195
2 CPallini 2,473
3 Richard MacCutchan 1,607
4 Abhinav S 1,505


Advertise | Privacy | Mobile
Web02 | 2.8.140814.1 | Last Updated 21 Feb 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100