Marina,
Good point, sorry about that...
I will add the others as parameters as soon as I can get the basic's
working.....
Here is the updated code that I am trying to execute:
Dim cmd = New OleDb.OleDbCommand("Insert into DocumentFullText values("
&
DocID & "," & PageNum & ",@OCRTEXT)", OLEConn)
With cmd.parameters
.add(New OleDbParameter("@OCRTEXT", OleDb.OleDbType.VarChar))
End With
cmd.parameters("@OCRTEXT").value = OCRText
Try
cmd.executeNonQuery()
Catch ex As Exception
MsgBox(ex.Message)
End Try
The error I get is:
"Exception has been thrown by the target of an invocation"
The stack trace is:
at System.Reflection.RuntimeMethodInfo.InternalInvoke(Object obj,
BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo
culture, Boolean isBinderDefault, Assembly caller, Boolean verifyAccess)
at System.Reflection.RuntimeMethodInfo.InternalInvoke(Object obj,
BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo
culture, Boolean verifyAccess)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags
invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters)
at Microsoft.VisualBasic.CompilerServices.LateBinding.FastCall(Object o,
MethodBase method, ParameterInfo[] Parameters, Object[] args, Type objType,
IReflect objIReflect)
at
Microsoft.VisualBasic.CompilerServices.LateBinding.InternalLateCall(Object
o, Type objType, String name, Object[] args, String[] paramnames, Boolean[]
CopyBack, Boolean IgnoreReturn)
at Microsoft.VisualBasic.CompilerServices.LateBinding.LateCall(Object o,
Type objType, String name, Object[] args, String[] paramnames, Boolean[]
CopyBack)
at aXs.OCR.SaveOCRDataForPage(Int64 DocID, Int32 PageNum, String
OCRText) in
C:\aXsInfo\Source\aXsNet3.0\aXs\aXsNet.vb:line 251
Many thanks again!
Steve
When you say 'throwing an error' in a newsgroup, you must say what the
error
and the error message are. Otherwise, that information is not very helpful
to the people trying to help you.
To run insert/update/delete statements, use ExecuteNonQuery. ExecuteReader
is meant for queries that return result sets, i.e. SELECT queries.
Also, as long as you are going for parameters, you might want to use
parameters for all your columns, including DocID and PageNum.
Can someone point me in the right direction here?
This is what I am trying to do based on your sugestions and what I could
find on the net. It is not working and throughing an error
Dim cmd = New OleDb.OleDbCommand("Insert into DocumentFullText
values(" &
DocID & "," & PageNum & ", @OCRTEXT)", OLEConn)
Dim p1 As OleDbParameter = cmd.Parameters.Add("@OCRTEXT",
OleDbType.LongVarChar)
p1.Value = OCRText
OLECommand.Connection = OLEConn
OLEDR = OLECommand.ExecuteReader
OLECommand.Dispose()
The table I am trying to insert into is 3 columns
DocID as Int
PageNumber as int
OCRTextData as varchar
message
Again, Marina is right on. Don't bother with the imbedded quotes
yourself.
Let ADO.NET do it for you with a Parameter. This also eliminates
(or
reduces) the chance of a SQL injection attack.
--
____________________________________
William (Bill) Vaughn
Author, Mentor, Consultant
Microsoft MVP
www.betav.com
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no
rights.
__________________________________
Well, one way is to replace every single quote in a parameter with 2.
That
should eliminate syntax errors, not to mention hacking attempts.
A more robust way though, is when you define your insert command
to
use
parameter placeholders, and then add parameters with appropriate
values.
Taking care of any special characters will all be done for you.
Thanks for the reply...
I am trying to build a generic method for just one table.. The
problem
is
I
am storing text for pages that were processed from an OCR engine and
I
get
alot
of ' and " in the text..... which just create havoc tyring to do
inserts....
Any other ideas?
You don't need to do a Fill. You would have to create a table with
the
appropriate schema, and then either define an Insert command,
or
use
the
commandbuilder, and then call Update on the data adapter.
If you ask me, if this is just for one insert, it will be
easier to
just
run
an insert statement. If you need a more robust, generic way of
doing
it,
you
will need to use the method I described above.
Is there a simple way to simply add a record to a table
without
needing
to
do a query, fill a dataset, add the row, etc....?
I do not want to use the "Insert into tablename......" as
shown
below...
SQLText="Insert into tablename (.......) value(........)"
ect......
OLEConn.Open()
OLECommand.CommandText = SQLText
OLECommand.Connection = OLEConn
OLEDR = OLECommand.ExecuteReader
OLECommand.Dispose()