By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,956 Members | 1,722 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,956 IT Pros & Developers. It's quick & easy.

ADODB Find/ Seek method in C# 2005

P: n/a
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


Oct 18 '07 #1
Share this Question
Share on Google+
7 Replies


P: n/a
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?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Bryan" <ca*******@lycos.comwrote in message
news:en**************@TK2MSFTNGP04.phx.gbl...
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


Oct 18 '07 #2

P: n/a
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.InvokeHandle r(Object target,
RoutedEventArgs routedEventArgs)
at System.Windows.EventRoute.InvokeHandlersImpl(Objec t source,
RoutedEventArgs args, Boolean reRaised)
at System.Windows.UIElement.RaiseEventImpl(RoutedEven tArgs args)
at System.Windows.UIElement.RaiseEvent(RoutedEventArg s e)
at System.Windows.Controls.Button.OnClick()
at
System.Windows.Controls.Primitives.ButtonBase.OnMo useLeftButtonUp(MouseButtonEventArgs
e)
at System.Windows.UIElement.OnMouseLeftButtonUpThunk( Object sender,
MouseButtonEventArgs e)
at
System.Windows.Input.MouseButtonEventArgs.InvokeEv entHandler(Delegate
genericHandler, Object genericTarget)
at System.Windows.RoutedEventArgs.InvokeHandler(Deleg ate handler,
Object target)
at System.Windows.RoutedEventHandlerInfo.InvokeHandle r(Object target,
RoutedEventArgs routedEventArgs)
at System.Windows.EventRoute.InvokeHandlersImpl(Objec t source,
RoutedEventArgs args, Boolean reRaised)
at System.Windows.UIElement.ReRaiseEventAs(RoutedEven tArgs args,
RoutedEvent newEvent)
at System.Windows.UIElement.OnMouseUpThunk(Object sender,
MouseButtonEventArgs e)
at
System.Windows.Input.MouseButtonEventArgs.InvokeEv entHandler(Delegate
genericHandler, Object genericTarget)
at System.Windows.RoutedEventArgs.InvokeHandler(Deleg ate handler,
Object target)
at System.Windows.RoutedEventHandlerInfo.InvokeHandle r(Object target,
RoutedEventArgs routedEventArgs)
at System.Windows.EventRoute.InvokeHandlersImpl(Objec t source,
RoutedEventArgs args, Boolean reRaised)
at System.Windows.UIElement.RaiseEventImpl(RoutedEven tArgs args)
at System.Windows.UIElement.RaiseEvent(RoutedEventArg s args, Boolean
trusted)
at System.Windows.Input.InputManager.ProcessStagingAr ea()
at System.Windows.Input.InputManager.ProcessInput(Inp utEventArgs
input)
at System.Windows.Input.InputProviderSite.ReportInput (InputReport
inputReport)
at System.Windows.Interop.HwndMouseInputProvider.Repo rtInput(IntPtr
hwnd, InputMode mode, Int32 timestamp, RawMouseActions actions, Int32 x,
Int32 y, Int32 wheel)
at System.Windows.Interop.HwndMouseInputProvider.Filt erMessage(IntPtr
hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
at System.Windows.Interop.HwndSource.InputFilterMessa ge(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.Internal RealCall(Delegate
callback, Object args, Boolean isSingleParameter)
at System.Windows.Threading.ExceptionWrapper.TryCatch When(Object
source, Delegate callback, Object args, Boolean isSingleParameter, Delegate
catchHandler)
at System.Windows.Threading.Dispatcher.InvokeImpl(Dis patcherPriority
priority, TimeSpan timeout, Delegate method, Object args, Boolean
isSingleParameter)
at System.Windows.Threading.Dispatcher.Invoke(Dispatc herPriority
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(Disp atcherFrame
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.Run UsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context( Object state)
at System.Threading.ExecutionContext.Run(ExecutionCon text
executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException:
Oct 18 '07 #3

P: n/a
Bryan wrote:
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
Oct 19 '07 #4

P: n/a
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.


"Bryan" <ca*******@lycos.comwrote in message
news:en**************@TK2MSFTNGP04.phx.gbl...
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


Oct 19 '07 #5

P: n/a
Any idea where I can find sample code? tutorials?

"Arne Vajhøj" <ar**@vajhoej.dkwrote in message
news:47***********************@news.sunsite.dk...
Bryan wrote:
> 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

Oct 19 '07 #6

P: n/a
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]
- mv*@spam.guard.caspershouse.com

"Bryan" <ca*******@lycos.comwrote in message
news:u%****************@TK2MSFTNGP06.phx.gbl...
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.InvokeHandle r(Object
target, RoutedEventArgs routedEventArgs)
at System.Windows.EventRoute.InvokeHandlersImpl(Objec t source,
RoutedEventArgs args, Boolean reRaised)
at System.Windows.UIElement.RaiseEventImpl(RoutedEven tArgs args)
at System.Windows.UIElement.RaiseEvent(RoutedEventArg s e)
at System.Windows.Controls.Button.OnClick()
at
System.Windows.Controls.Primitives.ButtonBase.OnMo useLeftButtonUp(MouseButtonEventArgs
e)
at System.Windows.UIElement.OnMouseLeftButtonUpThunk( Object sender,
MouseButtonEventArgs e)
at
System.Windows.Input.MouseButtonEventArgs.InvokeEv entHandler(Delegate
genericHandler, Object genericTarget)
at System.Windows.RoutedEventArgs.InvokeHandler(Deleg ate handler,
Object target)
at System.Windows.RoutedEventHandlerInfo.InvokeHandle r(Object
target, RoutedEventArgs routedEventArgs)
at System.Windows.EventRoute.InvokeHandlersImpl(Objec t source,
RoutedEventArgs args, Boolean reRaised)
at System.Windows.UIElement.ReRaiseEventAs(RoutedEven tArgs args,
RoutedEvent newEvent)
at System.Windows.UIElement.OnMouseUpThunk(Object sender,
MouseButtonEventArgs e)
at
System.Windows.Input.MouseButtonEventArgs.InvokeEv entHandler(Delegate
genericHandler, Object genericTarget)
at System.Windows.RoutedEventArgs.InvokeHandler(Deleg ate handler,
Object target)
at System.Windows.RoutedEventHandlerInfo.InvokeHandle r(Object
target, RoutedEventArgs routedEventArgs)
at System.Windows.EventRoute.InvokeHandlersImpl(Objec t source,
RoutedEventArgs args, Boolean reRaised)
at System.Windows.UIElement.RaiseEventImpl(RoutedEven tArgs args)
at System.Windows.UIElement.RaiseEvent(RoutedEventArg s args, Boolean
trusted)
at System.Windows.Input.InputManager.ProcessStagingAr ea()
at System.Windows.Input.InputManager.ProcessInput(Inp utEventArgs
input)
at System.Windows.Input.InputProviderSite.ReportInput (InputReport
inputReport)
at System.Windows.Interop.HwndMouseInputProvider.Repo rtInput(IntPtr
hwnd, InputMode mode, Int32 timestamp, RawMouseActions actions, Int32 x,
Int32 y, Int32 wheel)
at
System.Windows.Interop.HwndMouseInputProvider.Filt erMessage(IntPtr hwnd,
Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
at System.Windows.Interop.HwndSource.InputFilterMessa ge(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.Internal RealCall(Delegate
callback, Object args, Boolean isSingleParameter)
at System.Windows.Threading.ExceptionWrapper.TryCatch When(Object
source, Delegate callback, Object args, Boolean isSingleParameter,
Delegate catchHandler)
at System.Windows.Threading.Dispatcher.InvokeImpl(Dis patcherPriority
priority, TimeSpan timeout, Delegate method, Object args, Boolean
isSingleParameter)
at System.Windows.Threading.Dispatcher.Invoke(Dispatc herPriority
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(Disp atcherFrame
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.Run UsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context( Object state)
at System.Threading.ExecutionContext.Run(ExecutionCon text
executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException:

Oct 19 '07 #7

P: n/a
Nicholas,
I tried taking out quotes still I get same error..

Thank you

Bryan
Oct 19 '07 #8

This discussion thread is closed

Replies have been disabled for this discussion.