用于插入,删除,更新的Gridview代码 [英] Gridview code for insert,delete,update

查看:68
本文介绍了用于插入,删除,更新的Gridview代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在这里,我已经通过使用Gridview任务在设计中采用了Gridview,添加新列是通过使用DataSource生成的删除,更新,插入按钮的.

我已将删除,更新,插入命令写为-

Here I have taken Gridview in the design by using the Gridview task add new column I have generated delete,update,insert buttons by using the DataSource.

I have written command for delete,update,insert as -

DeleteCommand="DELETE FROM Empdetails WHERE (Empname =raghu)";


还有


And

UpdateCommand="UPDATE Empdetails SET Empid = 1865201, Empname = 'Reddy' WHERE (Empid = 1865200)" 


通过这样做,它是删除,仅更新特定的Empid,但是我需要代码来删除所有记录,并更新所有记录,我们单击Gridview行中的update any按钮.

我需要的代码仅用于Gridview delete,update,insert按钮.
例如此处-此Gridview

empname | empid | city |
raghu | 18652 | hyd |删除(按钮)|更新(按钮)|插入(按钮)
ram | 1547 | hyd |删除(按钮)|更新(按钮)|插入(按钮)

就像我有记录并删除,更新,插入按钮一样.

在这里,我只需要单击应更新的每一行中的更新的代码,同样也要删除,插入按钮.


By doing this it is deleting,updating only particular Empid, but I need code for deleting all the records,and updating all the records where we click the update any button in the row of Gridview.

The code which I need is only for in Gridview delete,update ,insert buttons.
For example here - Gridview in this

empname|empid|city|
raghu |18652|hyd| Delete(button)|Update(button)|insert(button)
ram |1547 |hyd|Delete(button)|Update(button)|insert(button)

Like I have records and delete,update,insert buttons.

Here I need code for only clicking the update in every row it should update, similarly delete ,insert buttons also.

推荐答案

参阅:

在ASP.NET 2.0中可编辑的GridView [ http://wiki.asp.net/page.aspx/1360/add -edit-update-delete-gridview/ [ http://www.aspdotnetcodes.com/GridView_Insert_Edit_Update_Delete.aspx [
refer:

Editable GridView in ASP.NET 2.0[^]
http://wiki.asp.net/page.aspx/1360/add-edit-update-delete-gridview/[^]

http://www.aspdotnetcodes.com/GridView_Insert_Edit_Update_Delete.aspx[^]

Hope this helps you definitely


您创建的命令有误,请为您的操作创建参数化命令.请点击链接以获取有关该主题的更多指导.

http://csharpdotnetfreak.blogspot.com/2009/06/gridview-objectdatasource-insert- update.html [ ^ ]

http://msdn.microsoft.com/en-us/library/ms972948.aspx [ ^ ]

http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.sqldatasource.updatecommand.aspx [
there is mistake in the commands you have created, kindly create parameterised commands for your operations. follow the link for more guidance over the topic.

http://csharpdotnetfreak.blogspot.com/2009/06/gridview-objectdatasource-insert-update.html[^]

http://msdn.microsoft.com/en-us/library/ms972948.aspx[^]

http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.sqldatasource.updatecommand.aspx[^]


mark as answer if solves your problem, it motivates :)


首先根据名称删除是错误的.您必须具有一个具有唯一值的字段.由于所有名称为"raghu"的记录都将被删除,因此最好使用Empid

其次,您的查询有误,应该是这样的
Firstly deleting on the basis of name is wrong. You must have a field holding unique value. As all the records with the name "raghu" will be deleted, better use Empid

Secondly your query is wrong, it should be like this
DeleteCommand="DELETE FROM Empdetails WHERE Empid=1011";


或您写的是什么


or for what you are writing

DeleteCommand="DELETE FROM Empdetails WHERE Empname =''raghu''";


这篇关于用于插入,删除,更新的Gridview代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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