自定义对象数据源DELETE方法不传递值 [英] Custom Object Data Source DELETE Method not passing a value

查看:54
本文介绍了自定义对象数据源DELETE方法不传递值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在努力让ObjectDataSource使用GridView。



到目前为止,我已经让Update命令工作正常,但删除命令不会通过正确的OrderID,它是订单表的主键。



这是HTML objectDataSource中更新和删除的代码



我的数据源是一个AccessDataBase所以我使用的是OLEDB



I have been trying to get an ObjectDataSource working with a GridView.

So far I have got the Update command working fine, but the Delete command will not pass the correct OrderID, which is the Primary Key for the Order Table.

Here is the code for the update and delete in the HTML objectDataSource

My Data Source is an AccessDataBase so I am using OLEDB

<asp:ObjectDataSource ID="odsOrderDetail" runat="server" TypeName="TrackerDotNet.App_Code.OrderDetailDAL" 
    EnablePaging="False" SelectMethod="LoadOrderDetailData"
    UpdateMethod="UpdateOrderDetails" 
    StartRowIndexParameterName="StartRowIndex" 
    MaximumRowsParameterName="MaximumRows" 
    OldValuesParameterFormatString="original_{0}" 
    DeleteMethod="DeleteOrderDetails" >
    <DeleteParameters>
      <asp:Parameter Name="OrderID" Type="Int32" />
    </DeleteParameters>
    <UpdateParameters>
      <asp:Parameter Name="OrderID" Type="Int32" />
      <asp:Parameter Name="ItemTypeID" Type="Int32" />
      <asp:Parameter Name="QuantityOrdered" Type="Double" />
      <asp:Parameter Name="PackagingID" Type="Int32" />
    </UpdateParameters>





....



定制中的代码更新的类工作正常:





....

The Code in the custom class for the Update works fine:

public bool UpdateOrderDetails(Int32 OrderID, Int32 ItemTypeID, double QuantityOrdered, Int32 PackagingID)
{
  string _sqlCmd = "UPDATE OrdersTbl SET ItemTypeID = ?, QuantityOrdered = ?, PackagingID = ? WHERE (OrderId = ?)";
  OleDbConnection _conn = new OleDbConnection(_connectionString);

   // add parameters in the order they appear in the update command
  OleDbCommand _cmd = new OleDbCommand(_sqlCmd, _conn);
  _cmd.Parameters.Add(new OleDbParameter { Value = ItemTypeID });
  _cmd.Parameters.Add(new OleDbParameter { Value = QuantityOrdered });
  _cmd.Parameters.Add(new OleDbParameter { Value = PackagingID });
  _cmd.Parameters.Add(new OleDbParameter { Value = OrderID });

  try
  {
    _conn.Open();
    if (_cmd.ExecuteNonQuery() == 0)
      return false;
  }
  catch (OleDbException e)
  {
    return false;
  }
  finally
  {
    _conn.Close();
  }

  return true;
}





删除命令是:





The Delete command is:

public bool DeleteOrderDetails(Int32 OrderID)
{
  string _sqlCmd = "DELETE FROM OrdersTbl WHERE (OrderId = ?)";
  OleDbConnection _conn = new OleDbConnection(_connectionString);

  // add parameters in the order they appear in the update command
  OleDbCommand _cmd = new OleDbCommand(_sqlCmd, _conn);
  _cmd.Parameters.Add(new OleDbParameter { Value = OrderID });

  try
  {
    _conn.Open();
    if (_cmd.ExecuteNonQuery() == 0)
      return false;
  }
  catch (OleDbException e)
  {
    return false;
  }
  finally
  {
    _conn.Close();
  }

  return true;
}





当我在Update中运行调试器时,所有变量都有有效值,并且它有效精细。但删除命令OrderID是0



我尝试重新绑定命令是编辑器,并尝试< asp:ControlParameter与OrderIDLabel在模板字段。



关于为什么会发生这种情况的任何想法?



When I run the debugger in the Update all the variables have valid values, and it works fine. But the Delete Command the OrderID is 0

I have tried re-binding the command is the editor and also tried <asp:ControlParameter with the OrderIDLabel that is in the template field.

Any ideas on why this is happening?

推荐答案

我仍然没有解决方案这个,有人吗?
I still have no solution to this, anyone?


嘿,请查看这个 http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.objectdatasource.deleteparameters.aspx [ ^ ]

我认为orderid参数设置不正确,希望这有帮助
Hey please check this http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.objectdatasource.deleteparameters.aspx[^]
I think the orderid parameter isn''t getting set correctly, hope this helps


这篇关于自定义对象数据源DELETE方法不传递值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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