Click here to Skip to main content
11,477,625 members (75,888 online)
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 22: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 Sergey Alexandrovich Kryukov 274
1 Richard Deeming 245
2 _duDE_ 165
3 Tomas Takac 150
4 Sascha Lefèvre 145
0 Sergey Alexandrovich Kryukov 7,675
1 OriginalGriff 7,256
2 Sascha Lefèvre 3,034
3 Maciej Los 2,491
4 Richard Deeming 2,305


Advertise | Privacy | Mobile
Web01 | 2.8.150520.1 | Last Updated 21 Feb 2013
Copyright © CodeProject, 1999-2015
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