Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8475717
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T17:58:07+00:00 2026-06-10T17:58:07+00:00

I have written this procedure in SQL and is working ALTER proc [dbo].[gridcombo] (@tabela

  • 0

I have written this procedure in SQL and is working

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

I use this procedure to populate a datagridview in C#

    public SqlConnection sqlcon = Tconex.GetConnection();
    public SqlDataAdapter da2 = new SqlDataAdapter();
    public DataTable dt1 = new DataTable(); 

        SqlParameter tabela = new SqlParameter("@tabela", SqlDbType.Int);
        tabela.Value = 1;
        SqlCommand llena = new SqlCommand("gridcombo", sqlcon);
        llena.Parameters.Add(tabela);
        llena.CommandType = CommandType.StoredProcedure;
        da2.SelectCommand = llena;
        da2.Fill(dt1);
        BindingSource bsource = new BindingSource();
        bsource.DataSource = dt1;
        dataGridView1.DataSource = bsource;
        dataGridView1.AutoGenerateColumns = true;
        sqlcon.Close();

When I change the tabela.value the datagrid is populated with one or another table, that works fine.

But I cannot edit the table via datagrid

        da2.UpdateCommand = new SqlCommandBuilder(da2).GetUpdateCommand();  
        da2.Update(dt1);
        sqlcon.Close();

What am I doing wrong? Why can’t I update the table??

Thanks for any help!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T17:58:08+00:00Added an answer on June 10, 2026 at 5:58 pm

    You must return your PrimaryKey of table in your SelectCommand, in order to generate correctly your update command

    Link : http://msdn.microsoft.com/fr-fr/library/system.data.sqlclient.sqlcommandbuilder%28v=vs.80%29.aspx

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have written a SQL Server stored procedure that includes a DateTime parameter. This
I have written grammar for a language (sample code below) //this is a procedure
I have written this code outside all functions: int l, k; for (l =
Scenario I have a stored procedure written in T-Sql using SQL Server 2005. SEL_ValuesByAssetName
I have written a single stored procedure that returns 2 tables: select * from
We have a function written in pl/sql(oracle) as below: CREATE OR REPLACE PROCEDURE folder_cycle_check
I have written a stored procedure in sql server 2005 that searches for results.
I have a stored procedure written in T-SQL and want to use a table
I'm new to development. In sql I have written a stored procedure and it
I have written the following piece of code ( sql clr stored procedure )

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.