Click here to Skip to main content
13,352,408 members (39,735 online)
Rate this:
Please Sign up or sign in to 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:-

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;

The Stored Procedure is like this:-

ALTER PROCEDURE dbo.update_item_by_id
	@item_id int,
	@cost_price float,
	@sell_price float,
	@dealer_id int
UPDATE       stock
SET                cost_price =@cost_price, sell_price =@sell_price, dealer_id =@dealer_id
WHERE        (item_id = @item_id)

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 16-Aug-12 21:18pm
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..
Rate this: bad
Please Sign up or sign in to vote.

Solution 1


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.

-Amit Gajjar
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

I suspect the following statement:

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

Try CombBox1.SelectedItem.Text instead value.


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)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web01 | 2.8.180111.1 | Last Updated 17 Aug 2012
Copyright © CodeProject, 1999-2018
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100