删除和更新网格行的问题 [英] Problem with deleting and update grid rows

查看:75
本文介绍了删除和更新网格行的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好

我写了一些webapp,我必须使用带有删除和编辑按钮的网格视图.
我尝试编写删除功能:

Hello everyone

I write some webapp and i must use grid view with deleting and edit button.
I try write deleting function :

try
           {


               connectionString = cnn;
               sqlConnection = new SqlConnection(connectionString);
               sqlConnection.Open();
               SqlCommand cmdDelete = new SqlCommand();
               string Delete = "DELETE FROM Teacher_Major WHERE Teacher_Major.major_id=@id";
               cmdDelete.Connection = sqlConnection;
               cmdDelete.CommandText = Delete;
               int id = int.Parse(gvMajor.Rows[e.RowIndex].Cells[1].Text.ToString());
               cmdDelete.Parameters.AddWithValue("@id", id);
               cmdDelete.ExecuteNonQuery();

           }
           catch (Exception exceptionObj)
           {

           }



但这返回错误:



but this return error :

Deleting is not supported by data source ''SqlDataSource1'' unless DeleteCommand is specified.



我该如何解决?
寻求帮助



How i can fix this ?
Thnx for help

推荐答案

您显然没有将DeleteCommand分配给SqlDataSource.如果这样做,则不需要编写的代码.

http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.sqldatasource.deletecommand.aspx [
You apparently did not assign a DeleteCommand to the SqlDataSource. If you do so you won''t need the code you have written.

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


这篇关于删除和更新网格行的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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