opens up another form (like a pop-up box) on top of "Calendar". The pop-up
box form is called "Memos" which is a stand-alone (doesn't communicate with
first form) database form with 3 drop-down boxes, a "Close" box and a rtb.
I had this working (see "Saving RTB content to SQL Server" in the
microsoft.publi c.vb.database forum) and then a user started to complain
about application crashes. On investigation I found that I couldn't
recreate the issue reliably but noticed that the problem seemed to occur
when the user typed alot of information into the rtb control. So, I tried
to write error code around the code in my "SaveMessag e" procedure, but the
funny thing is that the code doesn't error when it actually tries to save
the data (which I am doing in a referenced object I built), or when it goes
through the code to put the data in the rtb. If I step through the code
(without the error trapping) it makes it all the way to what I would expect
to be the end, and then I hit F8 at the last "Sub End" line thinking the
next thing I will see is the "Memos" form and instead I get an "unhandled
exception of type 'System.NullRef erenceException '... Object reference not
set to an instance of an object." error and the line it is stopping on is
"Public Class Calendar" from the "Calendar" form!!! I can still see my
"Memos" form in the fore-ground and that is the form it should have dropped
me to.
I came up with the idea of having thedatabase object return a "1" or "0"
depending on whether the data saved to the database correctly, and that
seems to return the "0" when I put in the long string into the rtb, but even
if I insert code to deal with the error condition, I still get the "Object
reference" error at the end just like before.
All I can think of is that this has something to do with the rtb not dealing
with the data properly and somehow destroying the actual rtb control on the
form. When my code tries to view it or clear it, it is no longer there and
that would explain the message. It would also explain my database object
returning a "0" properly in this instance. I had the field in SQL Server
set to "binary 1000" and expanded that to 2000, but no effect.
I hope that is enough info for you to go on. There are so many little
things here I almost need to send you the code. Look below for code
snippets of how I am performing certain tasks.
I hope you can help me.
Schoo
Here is how I call "Memos" from "Calendar": =============== ==
Private Sub MenuItem4_Click (ByVal....) Handles MenuItem4.Click
Dim memos as memos = New Memos
memos.show()
End Sub
=============== ==
Here is the call to the database object: =============== ==
Dim response as integer = oDBAccess.saveM essage(strCurMo nth, strCurYear,
strCurType, rtb1)
=============== ==
Here is the active code in the saveMessage function in the database object:
=============== ==
Try
If GetRecsScalar(" select count(*) from monthlymessages where
dtYear = " & dtYear & " and dtMonth = " & dtMonth & " and typeid=(select id
from type where type = '" & type & "')") > 0 Then
strSql = "update monthlymessages set message = @mess where
dtYear = " & dtYear & " and dtMonth = " & dtMonth & " and typeid=(select id
from type where type = '" & type & "')"
Else
strSql = "insert into monthlymessages select " & dtYear & ",
" & dtMonth & ", (select id from type where type = '" & type & "'), @mess"
End If
Dim rtf(999) As Byte
Dim s As New MemoryStream(rt f)
rtb.SaveFile(s, RichTextBoxStre amType.RichText )
Dim p(1) As SqlParameter
p(0) = New SqlParameter("@ mess", SqlDbType.Binar y, 1000)
p(0).Value = rtf
Microsoft.Appli cationBlocks.Da ta.SqlHelper.Ex ecuteNonQuery(o Settings.dbConn ,
CommandType.Tex t, strSql, p)
Catch
intResponse = 0
End Try
Return intResponse
=============== ==