ADODB Find/ Seek method in C# 2005

B

Bryan

Hi ,
I am using ADO (ADODB) with access database. Not sure what I am doing
wrong.here. Can anyone please help me?

string mdbFile = System.IO.Directory.GetCurrentDirectory() +" \\bTrack.mdb;"
ADODB.Connection conn = new ADODB.Connection();
ADODB.Recordset rs = new ADODB.Recordset();
string connString =string.Format("Provider=Microsoft.Jet.OLEDB.4.0; Data
Source={0}", mdbFile);
string query = "Select * from Client";
conn.ConnectionString = connString;
conn.Open(null, null, null, 0);
rs.Open(query, conn, ADODB.CursorTypeEnum.adOpenKeyset,
ADODB.LockTypeEnum.adLockOptimistic, -1);
rs.Find("ID='" + myID+"'", 0,
ADODB.SearchDirectionEnum.adSearchForward,null);==> Get COMException Error
here

Thank you

Bryan
 
N

Nicholas Paldino [.NET/C# MVP]

Bryan,

What is the exception error you are getting?

Also, do you have a need to select all the records at once? Why not
just filter based on the id?

Finally, why not use the classes in the System.Data.OleDb namespace?
 
B

Bryan

Hi Nicholas,
Here are the Error Details. Well I am using Microsoft Access
Database and I am new to c# , dont know lot about ADO.Net thats why I tried
to use ADODB instead of ADO.NET. I am trying to navigate to next record. If
you see the code I am opening recordset and find record which will match id
.. I dont know how to do this in ADO.NET

Thank you for your response.

Bryan



System.Runtime.InteropServices.COMException was unhandled
HelpLink="C:\\WINDOWS\\HELP\\ADO270.CHM#1240652"
Message="Application uses a value of the wrong type for the current
operation."
Source="ADODB.Recordset"
ErrorCode=-2146824867
StackTrace:
at ADODB.RecordsetClass.Find(String Criteria, Int32 SkipRecords,
SearchDirectionEnum SearchDirection, Object Start)
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(RoutedEventArgs args)
at System.Windows.UIElement.RaiseEvent(RoutedEventArgs e)
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(RoutedEventArgs args,
RoutedEvent newEvent)
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(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.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.RunInternal(Window window)
at System.Windows.Application.Run(Window window)
at System.Windows.Application.Run()
at System.AppDomain._nExecuteAssembly(Assembly assembly, String[]
args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence
assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
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:
 
?

=?ISO-8859-1?Q?Arne_Vajh=F8j?=

Bryan said:
Well I am using Microsoft Access
Database and I am new to c# , dont know lot about ADO.Net thats why I tried
to use ADODB instead of ADO.NET.

Switch to ADO.NET OLE DB provider.

Much easier.

Arne
 
S

sloan

Did you run a "auto up converter" to do that.

You probably need to google

DataSet
IDataReader

OleDBProvider.

There isn't really any good reason to use ADO in DotNet.

ADO.Net is not ADO.

You can also get the EnterpriseLibrary(.Data), and it will make using Access
(most datasources really).


Make the jump, dude.
 
N

Nicholas Paldino [.NET/C# MVP]

Bryan,

I think you would want to not encapsulate the ID field in quotes in the
call to Find. My guess is the ID field is an integer.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Bryan said:
Hi Nicholas,
Here are the Error Details. Well I am using Microsoft
Access Database and I am new to c# , dont know lot about ADO.Net thats why
I tried to use ADODB instead of ADO.NET. I am trying to navigate to next
record. If you see the code I am opening recordset and find record which
will match id . I dont know how to do this in ADO.NET

Thank you for your response.

Bryan



System.Runtime.InteropServices.COMException was unhandled
HelpLink="C:\\WINDOWS\\HELP\\ADO270.CHM#1240652"
Message="Application uses a value of the wrong type for the current
operation."
Source="ADODB.Recordset"
ErrorCode=-2146824867
StackTrace:
at ADODB.RecordsetClass.Find(String Criteria, Int32 SkipRecords,
SearchDirectionEnum SearchDirection, Object Start)
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(RoutedEventArgs args)
at System.Windows.UIElement.RaiseEvent(RoutedEventArgs e)
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(RoutedEventArgs args,
RoutedEvent newEvent)
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(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.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.RunInternal(Window window)
at System.Windows.Application.Run(Window window)
at System.Windows.Application.Run()
at System.AppDomain._nExecuteAssembly(Assembly assembly, String[]
args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence
assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
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:
 
B

Bryan

I do wanna make jump!! Well I am not really c# programmer. This is first
application I am trying to write in VS2005. Actually I am not writing c#
application, its WPF application I am trying to write. Thats why I cant use
BindingNavigator . I am trying to create class for client table and I am
trying to write navigation method in the class(Nest,Previous,Top,Bottom). I
am not sure what is right way to do it..

sloan--you said something about enterprise library. Can you please tell me
more?

Your help is appriciated..If anyone can find sample or tutorial that would
be great.
 
?

=?ISO-8859-1?Q?Arne_Vajh=F8j?=

Bryan said:
Any idea where I can find sample code? tutorials?

There are examples in the class library documentation that
comes with the SDK.

Arne
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top