【问题标题】:datagridview won't updatedatagridview 不会更新
【发布时间】:2014-04-14 20:53:14
【问题描述】:

我有这个数据网格视图:

使用此程序:

 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 不会进行更新。

【问题讨论】:

  • 更新后再次尝试运行dap.Fill

标签: c# sql sql-server visual-studio-2010


【解决方案1】:

你有连接到数据库吗?可能是 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");

希望对你有所帮助...

【讨论】:

    猜你喜欢
    • 2017-01-09
    • 1970-01-01
    • 1970-01-01
    • 2012-10-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-01-05
    相关资源
    最近更新 更多