ado_dotnet thread: OleDbCommand: exception with parameter of type LongVarWChar and empty String
I connect to an Access 2000 database, containing a table that has the
two fields CKey (type Text) and CValue (type Memo). The following code
generates an exception whenever the value for column CValue is an
empty string ('allow zero length' is set in mdb):
Dim cmd As New OleDbCommand()
cmd.Connection = TestConnection
cmd.CommandText = "INSERT INTO MyTable( CKey , CValue ) VALUES ( ?, ?
)"
Dim p1 As New OleDbParameter("@p1", OleDbType.VarWChar, 0,
ParameterDirection.Input, True, 0, 0, "CKey", DataRowVersion.Current,
"")
Dim p2 As New OleDbParameter("@p2", OleDbType.LongVarWChar, 0,
ParameterDirection.Input, False, 0, 0, "CValue",
DataRowVersion.Current, "")
p1.Value = Guid.NewGuid().ToString()
p2.Value = "" 'works if set to something else then empty string
cmd.Parameters.Add(p1)
cmd.Parameters.Add(p2)
TestConnection.Open()
cmd.ExecuteNonQuery() ' exception raised
TestConnection.Close()
The exception message is our old friend:
"Multiple-step OLE DB operation generated errors. Check each OLE DB
status value, if available. No work was done."
The exception does not occur if I change the type of parameter 2 from
LongVarWChar to VarWChar. This is in particular enjoying, because the
OleDbCommandBuilder generates parameters of type LongVarWChar for Memo
fields.
Does anybody know why this happens? Does it matter if I use VarWChar
in place of LongVarWChar?
Thanks,
Godwin.
PS: I am using 'Visual Studio Enterprise Architect V2002'