Click here to Skip to main content
15,890,506 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have two table
package(pac_id,package_bid,package_price) and tbl_bid(bid_id,lid,available_bid)

and i want to make like this..
when user select any package and then selected package's bid add into available_bid
hee i use like this query...
C#
("update tbl_bid set Availablebid = Availablebid + (select Package_Price from package where pac_id = e.commandargument,con) where l_id=1", con);

it will show error like (Incorrect syntax near ',')

i bind package table data in datalist...

thanks in advance
Posted
Updated 22-Jan-12 23:02pm
v2
Comments
AmitGajjar 23-Jan-12 5:11am    
not clear! improve your question.

Error is in your query....

("update tbl_bid set Availablebid = Availablebid + (select Package_Price from package where pac_id = e.commandargument,con) where l_id=1", con);


You have written two connections, one after select query another after total query...

But you should remove the con after select query, which is causing the problem syntax after comma (,)...
 
Share this answer
 
Comments
Suresh9724 23-Jan-12 6:00am    
still get error like ::

Incorrect syntax near '.'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Data.SqlClient.SqlException: Incorrect syntax near '.'.

Source Error:

Line 21: SqlCommand cmd = new SqlCommand("update tbl_bid set Availablebid = Availablebid + (select Package_Price from package where pac_id = Convert.ToInt32(e.CommandArgument)) where l_id=1 ", con);
Line 22: con.Open();
Line 23: cmd.ExecuteNonQuery();
Line 24: con.Close();
Line 25: }
Ok, wait I will post the answer. Don't worry....
you have used con object twice in the statement.
remove first con object.

Hope you will get the solution.

Feel free if any other doubt.
 
Share this answer
 
You are using "Convert.ToInt32()" inside sql query, but that is not a sql inbuilt function, it is in c#. So, you can do like...

C#
int pac_id = Convert.ToInt32(e.CommandArgument);


C#
string sqlQuery = "update tbl_bid 
set available_bid = available_bid + (select Package_Price from package where pac_id = '" + pac_id + "') 
where lid = 1";

SqlCommand cmd = new SqlCommand(sqlQuery, con);


Make sure all your column names are correct and "available_bid" and "Package_Price" should have same data type.

I have created tables and columns as you posted when you first asked the question like ...

package(pac_id,package_bid,package_price) and tbl_bid(bid_id,lid,available_bid)


And the query worked in my case..
 
Share this answer
 

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