2013-05-20 8 views
5

में MySqlDateTime मैं एक MySQLDateTime ऑब्जेक्ट की तुलना किसी अन्य MySqlDateTime ऑब्जेक्ट की तुलना करने की कोशिश कर रहा हूं, प्रत्येक दो अलग-अलग तालिकाओं से। मैं एक LINQ क्वेरी के अंदर यह सब करने के लिए कोशिश कर रहा हूँ, उदाहरण के लिए:LINQ क्वेरी

 var prodRowFindQuery = 
      from x in production.AsEnumerable() 
      where x.Field<MySqlDateTime>("date") == row.Field<MySqlDateTime>("date") && 
        x.Field<String>("device_id3") == row.Field<String>("device_id3") 
      select x; 

यह मैं एक संकलक त्रुटि देता है:

ऑपरेटर '==' प्रकार के 'ऑपरेंड के लिए लागू नहीं किया जा सकता MySql.Data

 var prodRowFindQuery = 
      from x in production.AsEnumerable() 
      where x.Field<MySqlDateTime>("date").ToString() == row.Field<MySqlDateTime>("date").ToString() && 
        x.Field<String>("device_id3") == row.Field<String>("device_id3") 
      select x; 

अब यह संकलित है, लेकिन मैं एक रन-टाइम ई मिलती है: .Types.MySqlDateTime 'और' MySql.Data.Types.MySqlDateTime '

तो फिर मैं यह कोशिश rror:

निर्दिष्ट कास्ट मान्य नहीं है।

स्टैक ट्रेस: ​​

IthacaDbTransferUtil.exe!IthacaDbTransferUtil.DataTableComparer.CompareTables.AnonymousMethod__0(System.Data.DataRow x = {System.Data.DataRow}) Line 34 C# 
System.Core.dll!System.Linq.Enumerable.WhereEnumerableIterator<System.Data.DataRow>.MoveNext() + 0x9c bytes 
IthacaDbTransferUtil.exe!IthacaDbTransferUtil.DataTableComparer.CompareTables(System.Data.DataTable aggregate = {System.Data.DataTable}, System.Data.DataTable production = {System.Data.DataTable}) Line 39 + 0x8b bytes C# 
IthacaDbTransferUtil.exe!IthacaDbTransferUtil.DbTransferWindowViewModel.CopyTestReliability() Line 177 + 0x94 bytes C# 
IthacaDbTransferUtil.exe!IthacaDbTransferUtil.DelegateCommand.Execute() Line 78 + 0x1f bytes C# 
IthacaDbTransferUtil.exe!IthacaDbTransferUtil.DelegateCommand.System.Windows.Input.ICommand.Execute(object parameter = null) Line 158 + 0xa bytes C# 
PresentationFramework.dll!System.Windows.Controls.Button.OnClick() + 0xaf bytes 
PresentationFramework.dll!System.Windows.Controls.Primitives.ButtonBase.OnMouseLeftButtonUp(System.Windows.Input.MouseButtonEventArgs e) + 0x117 bytes  
PresentationCore.dll!System.Windows.RoutedEventArgs.InvokeHandler(System.Delegate handler, object target) + 0x56 bytes  
PresentationCore.dll!System.Windows.EventRoute.InvokeHandlersImpl(object source, System.Windows.RoutedEventArgs args, bool reRaised) + 0x270 bytes  
PresentationCore.dll!System.Windows.UIElement.ReRaiseEventAs(System.Windows.DependencyObject sender = {System.Windows.Controls.Button}, System.Windows.RoutedEventArgs args = {System.Windows.Input.MouseButtonEventArgs}, System.Windows.RoutedEvent newEvent) + 0x183 bytes  
PresentationCore.dll!System.Windows.RoutedEventArgs.InvokeHandler(System.Delegate handler, object target) + 0x56 bytes  
PresentationCore.dll!System.Windows.EventRoute.InvokeHandlersImpl(object source, System.Windows.RoutedEventArgs args, bool reRaised) + 0x270 bytes  
PresentationCore.dll!System.Windows.UIElement.RaiseEventImpl(System.Windows.DependencyObject sender = {System.Windows.Controls.Button}, System.Windows.RoutedEventArgs args = {System.Windows.Input.MouseButtonEventArgs}) + 0x14e bytes 
PresentationCore.dll!System.Windows.UIElement.RaiseTrustedEvent(System.Windows.RoutedEventArgs args = {System.Windows.Input.MouseButtonEventArgs}) + 0x64 bytes 
PresentationCore.dll!System.Windows.Input.InputManager.ProcessStagingArea() + 0x431 bytes  
PresentationCore.dll!System.Windows.Input.InputProviderSite.ReportInput(System.Windows.Input.InputReport inputReport) + 0xfd bytes  
PresentationCore.dll!System.Windows.Interop.HwndMouseInputProvider.ReportInput(System.IntPtr hwnd, System.Windows.Input.InputMode mode, int timestamp, System.Windows.Input.RawMouseActions actions, int x, int y, int wheel) + 0x410 bytes 
PresentationCore.dll!System.Windows.Interop.HwndMouseInputProvider.FilterMessage(System.IntPtr hwnd = 396436, MS.Internal.Interop.WindowMessage msg = WM_LBUTTONUP, System.IntPtr wParam = 0, System.IntPtr lParam = 34472260, ref bool handled = false) + 0x388 bytes  
PresentationCore.dll!System.Windows.Interop.HwndSource.InputFilterMessage(System.IntPtr hwnd, int msg, System.IntPtr wParam, System.IntPtr lParam, ref bool handled) + 0x7c bytes 
WindowsBase.dll!MS.Win32.HwndWrapper.WndProc(System.IntPtr hwnd, int msg, System.IntPtr wParam, System.IntPtr lParam, ref bool handled) + 0x14a bytes  
WindowsBase.dll!MS.Win32.HwndSubclass.DispatcherCallbackOperation(object o) + 0x80 bytes  
WindowsBase.dll!System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate callback, object args, int numArgs) + 0x5e bytes 
WindowsBase.dll!MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(object source = {System.Windows.Threading.Dispatcher}, System.Delegate method, object args, int numArgs, System.Delegate catchHandler = null) + 0x47 bytes 
WindowsBase.dll!System.Windows.Threading.Dispatcher.LegacyInvokeImpl(System.Windows.Threading.DispatcherPriority priority, System.TimeSpan timeout, System.Delegate method, object args, int numArgs) + 0x2bc bytes 
WindowsBase.dll!MS.Win32.HwndSubclass.SubclassWndProc(System.IntPtr hwnd, int msg, System.IntPtr wParam, System.IntPtr lParam) + 0x140 bytes  
[Native to Managed Transition]  
[Managed to Native Transition]  
WindowsBase.dll!System.Windows.Threading.Dispatcher.PushFrameImpl(System.Windows.Threading.DispatcherFrame frame) + 0x112 bytes 
PresentationFramework.dll!System.Windows.Application.RunInternal(System.Windows.Window window) + 0x17a bytes  
PresentationFramework.dll!System.Windows.Application.Run() + 0x67 bytes 
IthacaDbTransferUtil.exe!IthacaDbTransferUtil.App.Main() + 0x77 bytes C# 
[Native to Managed Transition]  
[Managed to Native Transition]  
Microsoft.VisualStudio.HostingProcess.Utilities.dll!Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() + 0x5a bytes  
mscorlib.dll!System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state, bool preserveSyncCtx) + 0x285 bytes 
mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state, bool preserveSyncCtx) + 0x9 bytes  
mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state) + 0x57 bytes  
mscorlib.dll!System.Threading.ThreadHelper.ThreadStart() + 0x51 bytes  
[Native to Managed Transition]  

एक और उदाहरण मैं कोशिश की है:

निर्दिष्ट डाली मान्य नहीं है:

  var prodRowFindQuery = 
       from x in production.AsEnumerable() 
       where Convert.ToDateTime(x.Field<MySqlDateTime>("date")) == Convert.ToDateTime(row.Field<MySqlDateTime>("date")) && 
         x.Field<String>("device_id3") == row.Field<String>("device_id3") 
       select x; 

फिर भी एक रन-टाइम त्रुटि को जन्म देती है।

एक और उदाहरण:

  var prodRowFindQuery = 
       from x in production.AsEnumerable() 
       where x.Field<DateTime>("date") == row.Field<DateTime>("date") && 
         x.Field<String>("device_id3") == row.Field<String>("device_id3") 
       select x; 

एक ही रन-टाइम त्रुटि:

निर्दिष्ट डाली मान्य नहीं है।

किसी ने कहा के बारे में कुछ "तिथि" एक MySqlDateTime प्रकार नहीं किया जा रहा, मनोरंजन के लिए, यहाँ सबूत है कि यह है:

  var prodRowFindQuery = 
       from x in production.AsEnumerable() 
       where x.Field<String>("date") == row.Field<String>("date") && 
         x.Field<String>("device_id3") == row.Field<String>("device_id3") 
       select x; 

रन-समय अपवाद:

की वस्तु कास्ट करने में असमर्थ 'System.String' टाइप करने के लिए 'MySql.Data.Types.MySqlDateTime' टाइप करें।

मैंने कुछ अन्य चीजों की कोशिश की है और मेरे लिए कुछ भी काम नहीं करता है।

किसी भी मदद की बहुत सराहना की जाएगी,

सादर,

केली

+0

कृपया प्राप्त अपवाद का स्टैक-ट्रेस जोड़ें। –

+0

स्टैक ट्रेस जोड़ा गया – kformeck

+0

। ToString() प्रारूप ऑपरेटरों के बिना समर्थित नहीं हो सकता है। क्या आपने कोशिश की है।()? –

उत्तर

0

मैंने अंततः इस समस्या को हल किया।

छद्म कोड में, यहाँ है कैसे मैंने किया:

  1. बनाने दो नए DataTables
  2. एक DataTable पर एक का चयन करते हैं, तालिका
  3. क्लोन तालिका के लिए आवश्यक सभी डेटा में खींच ऐसा करने से:

    0123:

    officialTable = temporaryTable.Clone(); 
    
  4. ऐसा करके स्तंभ डाली

    officialTable.Columns["date"].DataType = typeof(String); 
    
  5. या तो तालिका पंक्तियों के माध्यम से फिर से घुमाएं, एक पंक्ति को दूसरी पंक्ति में कॉपी करें; या फिर सभी डेटा प्राप्त करने के लिए एक और चयन कथन करें, लेकिन इस बार, "डेटा" कॉलम स्वचालित रूप से इसके बजाय डाला जाएगा। वर्ष DataTable

मुझे आशा है कि के

  • निपटाने इस किसी बाहर किसी और मदद करता है।

  • 0

    उच्चतम संभावना है कि DataRow की "date" फ़ील्ड प्रकार MySqlDateTime की नहीं है, या "device_id3" फ़ील्ड प्रकार string का नहीं है ।

    +0

    एक और अधिक जानकारी है जो मदद कर सकती है: मुझे पता है कि "device_id3" निश्चित रूप से एक स्ट्रिंग है। तारीख के लिए, मैं पूरी तरह से यकीन नहीं है। मुझे हमेशा MySqlDateTime कास्टिंग त्रुटियां मिलती हैं जो मुझे अजीब लगता है क्योंकि जब मैं उस कॉलम से पूछता हूं, तो मैं कहता हूं "CAST (CHAR (50) के रूप में दिनांक) AS दिनांक" डेटटाइम फ़ील्ड को स्ट्रिंग फ़ील्ड में डालने से पहले इसे .NET तक पहुंचने से पहले। – kformeck

    0

    यदि कोई MySQLDateTime के लिए परिभाषित कोई समानता ऑपरेटर नहीं है तो आप या तो स्वयं को परिभाषित कर सकते हैं, या तुलना करने से पहले इसे मानक .NET डेटाटाइम ऑब्जेक्ट में परिवर्तित कर सकते हैं।

    +0

    मूल पोस्ट में स्टैक ट्रेस के बाद पोस्ट किए गए नए कोड उदाहरण देखें। मैं एक MyQqlDateTime से एक System.DateTime को LINQ क्वेरी के अंदर सफलतापूर्वक कैसे परिवर्तित करूं? – kformeck