私はこの手順を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にデータを入力します
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();
tabela.value
データグリッドに1つまたは別のテーブルが入力されていることを変更すると、正常に機能します。
しかし、datagridを介してテーブルを編集することはできません
da2.UpdateCommand = new SqlCommandBuilder(da2).GetUpdateCommand();
da2.Update(dt1);
sqlcon.Close();
私は何が間違っているのですか?テーブルを更新できないのはなぜですか?
助けてくれてありがとう!