数据网格中的问题 [英] Problem in datagrid

查看:84
本文介绍了数据网格中的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法更新数据网格中的数据.
它显示了更新选项,但是在赋予新值后,它没有从文本框中获取该值.

I am not able to update data in the datagrid.
Its showing the option to update but after giving new value its not taking that value from the text boxes.

protected void DataGrid1_UpdateCommand(object source, DataGridCommandEventArgs e)
{

    //OleDbConnection con;
    //OleDbCommand cmd;
    try
    {
        OleDbConnection con = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;data source=d:\\tanu\\database_hardware.mdb;");
        OleDbCommand cmd = new OleDbCommand();
        cmd.CommandText = "UPDATE additem SET name=@name, Item_qty=@Item_qty where Item_id=@Item_id";

        cmd.Parameters.Add("@name", OleDbType.VarChar).Value = ((TextBox)e.Item.Cells[1].Controls[0]).Text;
        cmd.Parameters.Add("@Item_qty", OleDbType.Numeric).Value = ((TextBox)e.Item.Cells[2].Controls[0]).Text;
        cmd.Parameters.Add("@Item_id", OleDbType.Numeric).Value = DataGrid1.DataKeys[e.Item.ItemIndex];

        cmd.Connection = con;
        cmd.Connection.Open();
        cmd.ExecuteNonQuery();
        cmd.Connection.Close();

        DataGrid1.EditItemIndex = -1;
        Binddata();
        
    }
    catch (Exception ex)
    {
        Response.Write(ex.Message);
    }
}


这是我的更新代码.请告诉我哪里错了


ya不幸的是,代码正在运行.
而且我无法弄错.


this is my code for update. Please tell me where its wrong


ya Unfortunately code is running.
And i m not able to get the mistake.
And where it is terrible ??

推荐答案

删除消息已损坏,但是我删除了此消息,因为OP投票赞成我提供帮助
Deleting messages is broken, but I removed this because the OP one voted me for offering to help


如果您要发布更多问题,请不要按"answer".

我确实回答了您的问题,并告诉您如何解决您的问题,但是您投票给我,所以我删除了它.您的代码很糟糕,变量名很糟糕,使用数据库的方法很糟糕.我会解雇任何上交此类代码的人.我会告诉您如何解决它,但是,您1投票给我.
Please don''t push ''answer'' if you''re posting more questions.

I did answer your question and tell you how to solve your problem, but you one voted me, so I deleted it. Your code is terrible, your variable names are terrible, your approach to using a database is terrible. I''d fire anyone who turned in code like this. I''d tell you how to fix it, but, you 1 voted me.


此代码是否正在运行?拥有这样的代码显然是很糟糕的设计,但是如果正在运行它,并且如果您可以在调试器中逐步执行它,并且看起来可行,那么主要的问题是,数据源是否不正确?更新了吗?
Is this code running ? It''s obviously terrible design to have code like this, but if it''s being run, and if you can step through it in the debugger, and it appears to work then the main question would be, is the data source not updated ?


这篇关于数据网格中的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆