Click here to Skip to main content
15,908,111 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
Comments
Surendra0x2 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

Change your query to:
C#
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.
 
Share this answer
 
Comments
[no name] 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 21-Feb-13 4:33am    
Did you convert it to a parametrised query?
Copy and paste your code!
[no name] 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)



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