我有这个datagridview:
使用此程序:
alter proc [dbo].[verfornecex1] (@FILA INT ) as
select idfornec,nome,conta,ativo from tbfornec
where Nome is not null and IdFornec = @fila
order by Nome
我写了这段代码:
SqlConnection conec2 = Tconex.Minifim();
DataSet grava = new DataSet();
SqlDataAdapter dap1 = new SqlDataAdapter();
SqlCommandBuilder constru9 = new SqlCommandBuilder(dap1);
SqlCommand llena11 = new SqlCommand("verfornecex1", conec2);
llena11.CommandType = CommandType.StoredProcedure;
SqlParameter tpd = new SqlParameter("@fila", SqlDbType.Int);
tpd.Value = vlz;
llena11.Parameters.Add(tpd);
dap1.SelectCommand = llena11;
dap1.Fill(grava, "fabricante");
DataRow dr3 = grava.Tables["fabricante"].NewRow();
dr3["ativo"] = 1;
dap1.Update(grava, "fabricante");
但那里出了点问题。我使用DataSet
因为DataTable
没有进行更新。
答案 0 :(得分:0)
你有连接到数据库吗?可能是conec2,但只是检查它
我认为您错过了DataTable功能?
SqlCommand llena11 = new SqlCommand("verfornecex",conec2);
SqlDataAdapter dap1 = new SqlDataAdapter();
dap1.SelectCommand = llena11;
DataTable grava = new DataTable();
dap1.Fill(grava, "fabricante");
dataGridView1.DataSource = grava;
dapt1.Update(grava, "fabricante");
希望这有点帮助...