C# 带有过程don'的Datagridview;t更新

C# 带有过程don'的Datagridview;t更新,c#,sql-server,stored-procedures,C#,Sql Server,Stored Procedures,我已经用SQL编写了这个过程,正在运行 ALTER proc [dbo].[gridcombo] (@tabela int) as /*1 Setores */ if (@tabela=1) begin select setor_id, setor_nome from tbl_setores end /*2 Atividade Economica */ if (@tabela=2) begin SELECT cnae_id, cnae_descricao FROM tbl_CNA

我已经用SQL编写了这个过程,正在运行

ALTER proc [dbo].[gridcombo] (@tabela int)
as

/*1 Setores */
if  (@tabela=1)
begin
select setor_id, setor_nome  from tbl_setores
end
/*2  Atividade Economica   */
if  (@tabela=2)
begin
SELECT cnae_id, cnae_descricao  FROM tbl_CNAE
end
我使用此过程在C中填充datagridview#

当我更改
tabela.value
时,datagrid中会填充一个或另一个表,这很好

但我无法通过datagrid编辑该表

        da2.UpdateCommand = new SqlCommandBuilder(da2).GetUpdateCommand();  
        da2.Update(dt1);
        sqlcon.Close();
我做错了什么?为什么我不能更新表


谢谢你的帮助

必须在
SelectCommand
中返回表的
PrimaryKey
,才能正确生成更新命令


链接:

谢谢我是亚历杭德罗我很乐意帮助你
        da2.UpdateCommand = new SqlCommandBuilder(da2).GetUpdateCommand();  
        da2.Update(dt1);
        sqlcon.Close();