Click here to Skip to main content
15,884,473 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more: , +
Hi guys,
I'm trying to update a table through stored procedure. I am having a page from which on button click a popup window appears. i'm sending a ID from the main page to the popup window using querystring, where the details from the table by ID is displayed in textbox. Here we can change the values and on button click the values should be updated to the table by the ID, where the ID = the Querystring value.

The Code on the button_click is like this:-

C#
SqlConnection con = new SqlConnection(Application["con_pth"].ToString());
        SqlCommand update_item = new SqlCommand("update_item_by_id", con);
        update_item.CommandType = CommandType.StoredProcedure;
        update_item.Parameters.Add("@item_id", SqlDbType.Int).Value = Request.QueryString["item_id"];
        update_item.Parameters.Add("@cost_price", SqlDbType.Float).Value = TextBox1.Text;
        update_item.Parameters.Add("@sell_price", SqlDbType.Float).Value = TextBox2.Text;
        update_item.Parameters.Add("@dealer_id", SqlDbType.VarChar).Value = ComboBox1.SelectedValue;
        
        con.Open();
        update_item.ExecuteNonQuery();
        con.Close();


The Stored Procedure is like this:-


SQL
ALTER PROCEDURE dbo.update_item_by_id
	
	(
	@item_id int,
	@cost_price float,
	@sell_price float,
	@dealer_id int
	)
	
AS
UPDATE       stock
SET                cost_price =@cost_price, sell_price =@sell_price, dealer_id =@dealer_id
WHERE        (item_id = @item_id)
	/* SET NOCOUNT ON */
	RETURN


But the problem is whn i click on the button the table is not getting updated with the new values. There is no error or exception thrown, but the update is also not done. What am i missing??? Please help..
Posted
Comments
chinta123 17-Aug-12 2:34am    
Your program is correct ,better you use try-catch block and set the break point and check ,then you can see where u r unable to get the output.
Aritra Nath 17-Aug-12 12:52pm    
could u please guide me on how to use breakpoint?? i havn't used it before.. thanks..

Hi,

Please check My Article : CRUD operation using ASP.Net and MySQL[^]

Although i have used MySQL as database but hope you can do it using SQL Server as well.

Thanks
-Amit Gajjar
 
Share this answer
 
I suspect the following statement:

update_item.Parameters.Add("@dealer_id", SqlDbType.VarChar).Value = ComboBox1.SelectedValue;

Try CombBox1.SelectedItem.Text instead value.

Thanks,

Kuthuparakkal
 
Share this answer
 
Comments
Aritra Nath 17-Aug-12 12:51pm    
I think this statemen is correct, because i have used it previously and got the proper values in table. Moreover if it was not, it should give some error or exception. but the code is running fine, only thing that the table is not getting updated.
Kuthuparakkal 22-Aug-12 23:56pm    
thanks u for the feedback

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