A
Adam Maltby
Hi,
I am trying to save some rtf code from an rtf field to a TEXT field on SQL2000.
The code I have been playing with (thanks to Nick for the originally supplied code!) is:
Sub DoByteConversion()
Dim pBytStuff As Byte() = StringToArray(Rtxt_readme.Rtf) 'convert rtf field to byte array
Dim pDBNConnection As OleDbConnection
Dim pDBCCommand As OleDbCommand
pDBNConnection = New OleDbConnection
pDBNConnection.ConnectionString = Globals.udl0Val 'take udk connection from Globals Class
Call pDBNConnection.Open()
If (pDBNConnection.State = ConnectionState.Open) Then
pDBCCommand = pDBNConnection.CreateCommand
pDBCCommand.CommandText = "UPDATE TestsConfig Set ReadMe = @bits Where Type = '" & TestSelected & "'"
pDBCCommand.CommandTimeout = 20
Call addParameter(pDBCCommand, "bits", pBytStuff)
If (pDBCCommand.ExecuteNonQuery() > 0) Then
'OPERATION WAS FINE!
End If
End If
End Sub
Public Function getOleDbType(ByVal iType As Type) As OleDbType
If (iType Is GetType(String)) Then
Return OleDbType.VarChar
ElseIf (iType Is GetType(Integer)) Then
Return OleDbType.Integer
ElseIf (iType Is GetType(Boolean)) Then
Return OleDbType.Boolean
ElseIf (iType Is GetType(Date)) Then
Return OleDbType.Date
ElseIf (iType Is GetType(Char)) Then
Return OleDbType.Char
ElseIf (iType Is GetType(Decimal)) Then
Return OleDbType.Decimal
ElseIf (iType Is GetType(Double)) Then
Return OleDbType.Double
ElseIf (iType Is GetType(Single)) Then
Return OleDbType.Single
ElseIf (iType Is GetType(Byte())) Then
Return OleDbType.Binary
ElseIf (iType Is GetType(Guid)) Then
Return OleDbType.Guid
End If
End Function
Public Sub addParameter(ByVal iCommand As OleDbCommand, ByVal iParameter As String, _
ByVal iValue As Object)
If (iCommand.CommandText.IndexOf(iParameter) <> -1) Then
Dim pODPParameter As OleDbParameter = _
iCommand.Parameters.Add(iParameter, getOleDbType(iValue.GetType))
pODPParameter.Value = iValue
End If
End Sub
However when I run this it I just get an unhandled exception in Data.Dll
Any ideas would be appreciated!
Cheers
Adam
I am trying to save some rtf code from an rtf field to a TEXT field on SQL2000.
The code I have been playing with (thanks to Nick for the originally supplied code!) is:
Sub DoByteConversion()
Dim pBytStuff As Byte() = StringToArray(Rtxt_readme.Rtf) 'convert rtf field to byte array
Dim pDBNConnection As OleDbConnection
Dim pDBCCommand As OleDbCommand
pDBNConnection = New OleDbConnection
pDBNConnection.ConnectionString = Globals.udl0Val 'take udk connection from Globals Class
Call pDBNConnection.Open()
If (pDBNConnection.State = ConnectionState.Open) Then
pDBCCommand = pDBNConnection.CreateCommand
pDBCCommand.CommandText = "UPDATE TestsConfig Set ReadMe = @bits Where Type = '" & TestSelected & "'"
pDBCCommand.CommandTimeout = 20
Call addParameter(pDBCCommand, "bits", pBytStuff)
If (pDBCCommand.ExecuteNonQuery() > 0) Then
'OPERATION WAS FINE!
End If
End If
End Sub
Public Function getOleDbType(ByVal iType As Type) As OleDbType
If (iType Is GetType(String)) Then
Return OleDbType.VarChar
ElseIf (iType Is GetType(Integer)) Then
Return OleDbType.Integer
ElseIf (iType Is GetType(Boolean)) Then
Return OleDbType.Boolean
ElseIf (iType Is GetType(Date)) Then
Return OleDbType.Date
ElseIf (iType Is GetType(Char)) Then
Return OleDbType.Char
ElseIf (iType Is GetType(Decimal)) Then
Return OleDbType.Decimal
ElseIf (iType Is GetType(Double)) Then
Return OleDbType.Double
ElseIf (iType Is GetType(Single)) Then
Return OleDbType.Single
ElseIf (iType Is GetType(Byte())) Then
Return OleDbType.Binary
ElseIf (iType Is GetType(Guid)) Then
Return OleDbType.Guid
End If
End Function
Public Sub addParameter(ByVal iCommand As OleDbCommand, ByVal iParameter As String, _
ByVal iValue As Object)
If (iCommand.CommandText.IndexOf(iParameter) <> -1) Then
Dim pODPParameter As OleDbParameter = _
iCommand.Parameters.Add(iParameter, getOleDbType(iValue.GetType))
pODPParameter.Value = iValue
End If
End Sub
However when I run this it I just get an unhandled exception in Data.Dll
Any ideas would be appreciated!
Cheers
Adam