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)

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:

CREATE PROCEDURE ChangeProductDetails
@Price int  , "you specify the data types of parameters according to your fields in database"
@Qty int,
@Desc nvarchar(50),
@Cname nvarchar(50),
@Pname nvarchar(50),
@Mno nvarchar(50)
 AS
update  prod_details 
set        price = @Price,
            qty=@Qty,
            desc = @Desc
where   cname = @Cname and pname= @Pname and mno = @Mno
GO

asp.net code

SqlCommand Cmd_UpdateProducts = new SqlCommand("ChangeProductDetails",con);
			Cmd_UpdateProducts.CommandType = CommandType.StoredProcedure;
			//passing parameters to command
			SqlParameter  Price= Cmd_UpdateProducts.Parameters.Add("@Price",SqlDbType.Int);
			Price.Value = txt_Price.Text;
			SqlParameter Qty = Cmd_UpdateProducts.Parameters.Add("@Qty",SqlDbType.Int);
			Qty.Value = txt_Qty.Text;
			SqlParameter desc = Cmd_UpdateProducts.Parameters.Add("@Desc",SqlDbType.NVarChar);
			desc.Value = txt_desc.Text;
SqlParameter Cname = Cmd_UpdateProducts.Parameters.Add("@Cname",SqlDbType.NVarChar);
			Cname.Value = txt_Cname.Text;
SqlParameter Pname = Cmd_UpdateProducts.Parameters.Add("@Pname",SqlDbType.NVarChar);
			Pname.Value = txt_Pname.Text;
SqlParameter Mno= Cmd_UpdateProducts.Parameters.Add("@Mno",SqlDbType.NVarChar);
			Mno.Value = txt_Mno.Text;
			con.Open();
			Cmd_UpdateProducts.ExecuteNonQuery();
			con.Close();

hope it usefull

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

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.

Hi,
coz desc is reserved keyword.

but you can still use it.
so change it to

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.