select count(*) from myTable where done=0

Posts   
 
    
stuarty
User
Posts: 15
Joined: 15-Dec-2008
# Posted on: 26-Jan-2009 17:11:45   

hi how do I do this query



select count(*) from myTable where done=0

I am using the lastest version and the adapter

I am really struggling with this at the moment

TIA

Stuart

Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 26-Jan-2009 17:30:57   
DataAccessAdapter adapter = new DataAccessAdapter();
int count = (int)adapter.GetScalar(MyTableFields.Id, null, AggregateFunction.CountRow, (MyTableFields.Done == 0));

(Edit) Also you can use the DataAccessAdapter's GetDBCount() method.

stuarty
User
Posts: 15
Joined: 15-Dec-2008
# Posted on: 26-Jan-2009 17:56:23   

hi I am now getting the error "Specified cast is not valid" confused confused thanks Stuart

Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 26-Jan-2009 18:03:22   

Please post the code you tried, the complete exception text and the stack trace.

Did you check the GetDBCount() route?

stuarty
User
Posts: 15
Joined: 15-Dec-2008
# Posted on: 26-Jan-2009 18:10:56   

  DataAccessAdapter adapter = new DataAccessAdapter();
           int  count = (int)adapter.GetScalar(BarcodesFields.BarcodePk, null, AggregateFunction.CountRow, (BarcodesFields.Mydown == 0));
            return count;


error

System.InvalidCastException was unhandled Message="Specified cast is not valid." Source="apcsigprocess" StackTrace: at apcsigprocess.barcodesProcess.GetTotalUnprocessed() in F:\vs2008liveProjects2009\apcsigllblgen\process\apcsigprocess\barcodesProcess.cs:line 36 at apcsigprocess.sigProcess.GetTotalUnprocessed() in F:\vs2008liveProjects2009\apcsigllblgen\process\apcsigprocess\apcsigprocess.cs:line 81 at wpfdownloader.Window1.btnTest_Click(Object sender, RoutedEventArgs e) in F:\wpf\downloader\wpfdownloader\wpfdownloader\Window1.xaml.cs:line 149 at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs) at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised) at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args) at System.Windows.UIElement.RaiseEvent(RoutedEventArgs e) at System.Windows.Controls.Primitives.ButtonBase.OnClick() at System.Windows.Controls.Button.OnClick() at System.Windows.Controls.Primitives.ButtonBase.OnMouseLeftButtonUp(MouseButtonEventArgs e) at System.Windows.UIElement.OnMouseLeftButtonUpThunk(Object sender, MouseButtonEventArgs e) at System.Windows.Input.MouseButtonEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget) at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target) at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs) at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised) at System.Windows.UIElement.ReRaiseEventAs(DependencyObject sender, RoutedEventArgs args, RoutedEvent newEvent) at System.Windows.UIElement.CrackMouseButtonEventAndReRaiseEvent(DependencyObject sender, MouseButtonEventArgs e) at System.Windows.UIElement.OnMouseUpThunk(Object sender, MouseButtonEventArgs e) at System.Windows.Input.MouseButtonEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget) at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target) at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs) at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised) at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args) at System.Windows.UIElement.RaiseEvent(RoutedEventArgs args, Boolean trusted) at System.Windows.Input.InputManager.ProcessStagingArea() at System.Windows.Input.InputManager.ProcessInput(InputEventArgs input) at System.Windows.Input.InputProviderSite.ReportInput(InputReport inputReport) at System.Windows.Interop.HwndMouseInputProvider.ReportInput(IntPtr hwnd, InputMode mode, Int32 timestamp, RawMouseActions actions, Int32 x, Int32 y, Int32 wheel) at System.Windows.Interop.HwndMouseInputProvider.FilterMessage(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled) at System.Windows.Interop.HwndSource.InputFilterMessage(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled) at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled) at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o) at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Boolean isSingleParameter) at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Boolean isSingleParameter, Delegate catchHandler) at System.Windows.Threading.Dispatcher.WrappedInvoke(Delegate callback, Object args, Boolean isSingleParameter, Delegate catchHandler) at System.Windows.Threading.Dispatcher.InvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Boolean isSingleParameter) at System.Windows.Threading.Dispatcher.Invoke(DispatcherPriority priority, Delegate method, Object arg) at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam) at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg) at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame) at System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame frame) at System.Windows.Threading.Dispatcher.Run() at System.Windows.Application.RunDispatcher(Object ignore) at System.Windows.Application.RunInternal(Window window) at System.Windows.Application.Run(Window window) at System.Windows.Application.Run() at wpfdownloader.App.Main() in F:\wpf\downloader\wpfdownloader\wpfdownloader\obj\Debug\App.g.cs:line 0 at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args) at System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args) at System.Runtime.Hosting.ManifestRunner.Run(Boolean checkAptModel) at System.Runtime.Hosting.ManifestRunner.ExecuteAsAssembly() at System.Runtime.Hosting.ApplicationActivator.CreateInstance(ActivationContext activationContext, String[] activationCustomData) at System.Runtime.Hosting.ApplicationActivator.CreateInstance(ActivationContext activationContext) at System.Activator.CreateInstance(ActivationContext activationContext) at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssemblyDebugInZone() at System.Threading.ThreadHelper.ThreadStart_Context(Object state) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) at System.Threading.ThreadHelper.ThreadStart() InnerException:

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 27-Jan-2009 08:09:43   

LLBLGen version an runtime library version?

Also, make sure you are referencing the correct version of LLBLGen runtime libraries on your project.

David Elizondo | LLBLGen Support Team
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39859
Joined: 17-Aug-2003
# Posted on: 27-Jan-2009 14:04:35   

The scalar returns null I think, which isn't castable to int, or it returns another type which isn't castable to int directly. PLease store the value into an object type variable first, then in the debugger check what the type is of the value returned by the scalar.

Frans Bouma | Lead developer LLBLGen Pro
stuarty
User
Posts: 15
Joined: 15-Dec-2008
# Posted on: 27-Jan-2009 17:19:26   

Hi I tracked this down to the fact that I generated the code against the live database, but the test database was not quite the same thanks for the help Stuart