Alex,
Does this work for commands that become InsertCommands or UpdateCommands? I can get the SET commands to stick when I just do straight SQL statements (like running an INSERT command directly through the CommandText of a SelectCommand).
But when I fill a DataTable and then set the InsertCommand of the data adapter, NULL values trigger an error when the Update method tries to insert a new record...
Do you use your Command objects with the Update method and have it work?
Thanks,
JoeK
>hi Joe do the following after you open the oledb connection in .net issue a SET NULL OFF,
>What I did was in my Framework on my basedataobject class this is my OpenConnection method.
>
> Sub OpenConnection()
> Me.Command.Parameters.Clear()
> If Me.Connection.State <> ConnectionState.Open Then
> Me.Connection.Open()
> End If
> If Me.Connection.State = ConnectionState.Open Then
> Me.Connections += 1
> Me.Command.CommandText = "SET DEFAULT TO (""" & Me.DataDir& """)"
> Me.Command.ExecuteScalar()
> Me.Command.CommandText = "SET EXCLUSIVE OFF"
> Me.Command.ExecuteScalar()
> Me.Command.CommandText = "SET DELETE ON"
> Me.Command.ExecuteScalar()
> Me.Command.CommandText = "SET NULL OFF"
> Me.Command.ExecuteScalar()
> Me.Command.CommandText = "SET MULTILOCKS ON"
> Me.Command.ExecuteScalar()
> Me.Command.CommandText = "SET EXACT ON"
> Me.Command.ExecuteScalar()
> Me.Command.CommandText = "SET REPROCESS TO 200"
> Me.Command.ExecuteScalar()
> Me.Command.CommandText = "SET REPROCESS TO 200 SYSTEM"
> Me.Command.ExecuteScalar()
> End If
> End Sub
>
>
>
>>Hey all,
>>
>>I have another .NET issue. I built a DBFUtil object that initializes the SelectCommand, InsertCommand, UpdateCommand, and DeleteCommand objects in a DataAdapter to all use the same VFPOLEDB connection. Everything works fine, and I can SELECT, INSER, UPDATE, and DELETE using a DataTable hooked to a DataGridView.
>>
>>But when I try to add a new record by entering a new row in the grid, I get NULL errors unless I fill in every field that is being added. There are no constraints on the DBF (it is a free table), and I know new rows are inserted properly if I fill everything in.
>>
>>I had the same issue with straight SELECT statements, and got around it by issuing a "SET NULL OFF" in the SelectCommand object using ExecuteNonQuery(). For SELECTs, I can have NULLs all over (e.g. when running LEFT JOINS), but if I run the same SET NULL OFF for InsertCommand and UpdateCommand as well, I am still getting NULL errors from the OleDb provider when adding or updating records involving NULLs.
>>
>>Obviously, I can get around this by making sure I don't have NULLs involved. *smile* But I was wondering if there was another way? Frankly, sometimes NULLs are very useful, as in having a logical field that can be true, false, or simply unanswered. I need to get NULLs working if I can, for creates, reads, updates, and deletes...
>>
>>Thanks,
>>JoeK