Update Command

Reply

Join Date: Mar 2008
Posts: 4
Reputation: Enjoy is an unknown quantity at this point 
Solved Threads: 0
Enjoy Enjoy is offline Offline
Newbie Poster

Update Command

 
0
  #1
Oct 8th, 2008
Hi all,
I am using asp and vb and back end is SQL .
I am getting syntax error in update command. Error is Incorrect Syntax near keyword "desc".
Can anyone debug this.
R can you tell me an alternative way to update record in database.
I have to check 3conditions in order to update a record.
This is the statement i have given.

com = New SqlCommand("Update prod_details Set price ='" & price.Text & "',qty='" & qty.Text & "',desc='" & desc.Text & "' where cname='" & cname.Text & "' and pname= '" & pname.Text & "' and mno= '" & mno.Text & "'", con)
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 6
Reputation: zezo is an unknown quantity at this point 
Solved Threads: 0
zezo's Avatar
zezo zezo is offline Offline
Newbie Poster

Re: Update Command

 
0
  #2
Oct 9th, 2008
com = New SqlCommand("Update prod_details Set price ='" & price.Text & "',qty='" & qty.Text & "',desc='" & desc.Text & "' where cname='" & cname.Text & "' and pname= '" & pname.Text & "' and mno= '" & mno.Text & "'", con)

try type new not New
and add ; at the end of statement

If you need another way:
on my i use stored procedure and pass values as a parameter and it is more accurate than execute and pass command from .net application.
here is the code:
database code:
  1. CREATE PROCEDURE ChangeProductDetails
  2. @Price int , "you specify the data types of parameters according to your fields in database"
  3. @Qty int,
  4. @Desc nvarchar(50),
  5. @Cname nvarchar(50),
  6. @Pname nvarchar(50),
  7. @Mno nvarchar(50)
  8. AS
  9. update prod_details
  10. set price = @Price,
  11. qty=@Qty,
  12. desc = @Desc
  13. where cname = @Cname and pname= @Pname and mno = @Mno
  14. GO
asp.net code
  1. SqlCommand Cmd_UpdateProducts = new SqlCommand("ChangeProductDetails",con);
  2. Cmd_UpdateProducts.CommandType = CommandType.StoredProcedure;
  3. //passing parameters to command
  4. SqlParameter Price= Cmd_UpdateProducts.Parameters.Add("@Price",SqlDbType.Int);
  5. Price.Value = txt_Price.Text;
  6. SqlParameter Qty = Cmd_UpdateProducts.Parameters.Add("@Qty",SqlDbType.Int);
  7. Qty.Value = txt_Qty.Text;
  8. SqlParameter desc = Cmd_UpdateProducts.Parameters.Add("@Desc",SqlDbType.NVarChar);
  9. desc.Value = txt_desc.Text;
  10. SqlParameter Cname = Cmd_UpdateProducts.Parameters.Add("@Cname",SqlDbType.NVarChar);
  11. Cname.Value = txt_Cname.Text;
  12. SqlParameter Pname = Cmd_UpdateProducts.Parameters.Add("@Pname",SqlDbType.NVarChar);
  13. Pname.Value = txt_Pname.Text;
  14. SqlParameter Mno= Cmd_UpdateProducts.Parameters.Add("@Mno",SqlDbType.NVarChar);
  15. Mno.Value = txt_Mno.Text;
  16. con.Open();
  17. Cmd_UpdateProducts.ExecuteNonQuery();
  18. con.Close();
hope it usefull
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 1
Reputation: ganesh_212005 is an unknown quantity at this point 
Solved Threads: 0
ganesh_212005 ganesh_212005 is offline Offline
Newbie Poster

Re: Update Command

 
0
  #3
Oct 10th, 2008
[QUOTE=Enjoy;707992]Hi all,
I am using asp and vb and back end is SQL .
I am getting syntax error in update command. Error is Incorrect Syntax near keyword "desc".
Can anyone debug this.
R can you tell me an alternative way to update record in database.
I have to check 3conditions in order to update a record.
This is the statement i have given.

[B]com = New SqlCommand("Update prod_details Set price ='" & price.Text & "',qty='" & qty.Text & "',desc='" & desc.Text & "' where cname='" & cname.Text & "' and pname= '" & pname.Text & "' and mno= '" & mno.Text & "'"), con
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 144
Reputation: sierrainfo is an unknown quantity at this point 
Solved Threads: 9
sierrainfo sierrainfo is offline Offline
Junior Poster

Re: Update Command

 
0
  #4
Nov 18th, 2008
com = New SqlCommand("Update prod_details Set price ='" & price.Text & "',qty='" & qty.Text & "',desc='" & desc.Text & "' where cname='" & cname.Text & "' and pname= '" & pname.Text & "' and mno= '" & mno.Text & "'", con)

change desc field name in your table
coz desc is reserved keyword.
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 182
Reputation: Kusno is an unknown quantity at this point 
Solved Threads: 15
Kusno's Avatar
Kusno Kusno is offline Offline
Junior Poster

Re: Update Command

 
0
  #5
Nov 19th, 2008
Hi,
coz desc is reserved keyword.

but you can still use it.
so change it to
  1. com = New SqlCommand("Update prod_details Set price ='" & price.Text & "',qty='" & qty.Text & "',[desc]='" & desc.Text & "' where cname='" & cname.Text & "' and pname= '" & pname.Text & "' and mno= '" & mno.Text & "'", con)

Thanks.
NEVER NEVER NEVER GIVE UP
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:




Views: 2396 | Replies: 4
Thread Tools Search this Thread



Tag cloud for ASP.NET
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC