通过asp.net中的存储过程更新表 [英] Updating a table through stored procedure in asp.net

查看:104
本文介绍了通过asp.net中的存储过程更新表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,
我正在尝试通过存储过程更新表.我有一个页面,从该页面上单击按钮,将显示一个弹出窗口.我正在使用查询字符串将ID从主页发送到弹出窗口,其中按ID在表中显示的详细信息显示在文本框中.在这里,我们可以更改值,然后单击按钮,应通过ID将值更新到表中,其中ID = Querystring值.

button_click上的代码如下:-

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..

推荐答案



请检查我的文章":使用ASP.Net和MySQL的CRUD操作 [ ^ ]

虽然我已经将MySQL用作数据库,但希望您也可以使用SQL Server来实现.

谢谢
-Amit Gajjar
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


我怀疑以下陈述:

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

尝试使用CombBox1.SelectedItem.Text代替value.

谢谢,

Kuthuparakkal
I suspect the following statement:

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

Try CombBox1.SelectedItem.Text instead value.

Thanks,

Kuthuparakkal


这篇关于通过asp.net中的存储过程更新表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆