私はデータベースベースのデスクトップアプリケーションを作成し、problem..Actuallyで立ち往生していますとの比較にnullを返します...C#のDataContext私はLINQのに新しいです日付
if (OP == "Delete")
{
tb = DB.TblPurchase.FirstOrDefault(e => e.PID.Equals(ID) || e.PItemName.Equals(ItemName) || e.PCategory.Equals(Category) || e.PDate.Equals(Date)); // returns null on comparing date
DB.Delete(tb);
return "Deleted";
}
else if (OP == "Search")
{
tb = DB.TblPurchase.FirstOrDefault(e => e.PID.Equals(ID) || e.PItemName.Equals(ItemName) || e.PCategory.Equals(Category) || e.PDate == Date); // returns null on comparing date as well
return tb;
}
機能の開始:
`public object AUDS_Purchase(string OP, int? ID = null, string ItemName = "",string Category = "", string Supplier = "", DateTime? Date = null, int ? Rate = null, int? Quantity = null, int? Total = null)
{
using(var DB = new MYDBDB())
{
TblPurchase tb = null;`
機能の呼び出し:注
`dynamic _ID = Cmb_Search_ItemID.SelectedIndex == -1 ? null : Cmb_Search_ItemID.SelectedValue;
dynamic _ItemName = Cmb_Search_ItemName.SelectedIndex == -1 ? null : Cmb_Search_ItemName.SelectedValue.ToString();
dynamic _ItemCategory = Cmb_Search_ItemCategory.SelectedIndex == -1 ? null : Cmb_Search_ItemCategory.SelectedValue.ToString();
dynamic _Date = Search_Item_Date;
dynamic res;
if (Search_Item_Date.Checked == false)
{
if (_ID != null || _ItemName != null || _ItemCategory != null)
{
res = tb.AUDS_Inventory("Search", Convert.ToInt32(_ID), _ItemName, _ItemCategory);
tb.ShowNewData(metroGrid1, res);
}
else
{
MetroMessageBox.Show(this, "No Value Given\nSelect a value", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}
else
{
res = tb.AUDS_Inventory("Search", Convert.ToInt32(_ID), _ItemName, _ItemCategory, Date:_Date);
tb.ShowNewData(metroGrid1, res);
}`
を:私はtbがあるため、ヌルであると確信しています私は、ブレークポイントを使用し...
私のテーブルにレコードが含まれています:Picture prove
すべてがデータベースとテーブルで正常に動作します...
これはところで、私の最初の投稿です。..事前に感謝 :)
ようこそStackOverflow。 [How to Ask](https://stackoverflow.com/help/how-to-ask)を読んで、エラーの詳細とこのエラーを表示している行を含めてください。 – Antimony
返信してリンクしてくれてありがとうございました...最初のコードでコメントを確認してください "if(OP ==" Delete ")" –