H
HaggardPete
Well Im fairly new to .NET but it seems to me that there is little/
no advantage to using the update, delete, insert methods of a data
adaptor at all. The commandbuilder seems not to work in many
real-world scenarios so you have to code the various commands
anyway. And if (for example) the update command is invalid the
update fails without a warning which makes debugging a nightmare.
So why bother with the adaptor?. Just issue the command directly. Its
easy to write a one line function call to process an SQL string -
and you can see whats happening.
RunSQL(OleDbConnection1, "UPDATE payments SET removed=1 WHERE pay_key
= " & Str(nRef))
Where RunSQL is along the lines of :
Public Function RunSQL(ByVal cn As OleDb.OleDbConnection, ByVal
sql As String) As Integer
'
'Run command text against given connection. Why doesnt .net
just do this !
'
Try
Dim sqlCmd As New OleDb.OleDbCommand()
RunSQL = 0
If cn.State = ConnectionState.Open Then
cn.Close()
End If
cn.Open()
With sqlCmd
.CommandType = CommandType.Text
.CommandText = sql
.Connection = cn
End With
RunSQL = sqlCmd.ExecuteNonQuery()
Catch e As Exception
MsgBox("Database command " & sql & " ended with
the error " & vbCrLf & e.Message & vbCrLf & vbCrLf
& e.StackTrace)
Finally
cn.Close()
End Try
End Function
I would be more than happy to be convinced otherwise but right now
I'm just struggling to see the point of data adaptors at all ...
no advantage to using the update, delete, insert methods of a data
adaptor at all. The commandbuilder seems not to work in many
real-world scenarios so you have to code the various commands
anyway. And if (for example) the update command is invalid the
update fails without a warning which makes debugging a nightmare.
So why bother with the adaptor?. Just issue the command directly. Its
easy to write a one line function call to process an SQL string -
and you can see whats happening.
RunSQL(OleDbConnection1, "UPDATE payments SET removed=1 WHERE pay_key
= " & Str(nRef))
Where RunSQL is along the lines of :
Public Function RunSQL(ByVal cn As OleDb.OleDbConnection, ByVal
sql As String) As Integer
'
'Run command text against given connection. Why doesnt .net
just do this !
'
Try
Dim sqlCmd As New OleDb.OleDbCommand()
RunSQL = 0
If cn.State = ConnectionState.Open Then
cn.Close()
End If
cn.Open()
With sqlCmd
.CommandType = CommandType.Text
.CommandText = sql
.Connection = cn
End With
RunSQL = sqlCmd.ExecuteNonQuery()
Catch e As Exception
MsgBox("Database command " & sql & " ended with
the error " & vbCrLf & e.Message & vbCrLf & vbCrLf
& e.StackTrace)
Finally
cn.Close()
End Try
End Function
I would be more than happy to be convinced otherwise but right now
I'm just struggling to see the point of data adaptors at all ...