Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ASP.NET SQL-Server , +
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;
        
        con.Open();
        update_item.ExecuteNonQuery();
        con.Close();
 
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
	)
	
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 16-Aug-12 20:18pm
Comments
chinta123 at 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 at 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
good
Please Sign up or sign in to vote.

Solution 1

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
  Permalink  
Rate this: bad
good
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.
 
Thanks,
 
Kuthuparakkal
  Permalink  
Comments
Aritra Nath at 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 at 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
0 OriginalGriff 395
1 DamithSL 218
2 Sergey Alexandrovich Kryukov 215
3 Dave Kreskowiak 200
4 Maciej Los 195


Advertise | Privacy | Mobile
Web04 | 2.8.140709.1 | Last Updated 17 Aug 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid