G
Guest
Can't addnew in child grids.
Haven't been progressing on this lately because of the Holy Days in Israel
and the call of other work.
Kevin Yu has been instrumental in helping me so far.
Have a keywordset table bound to textboxes and a checkbox, with the usual
buttons for moving position, adding, deleting, updating the dataset and
updating the database through the data adapter.
All work fine.
There are two child tables, keywords and searchphrase, related in the
dataset's xsd file and in the database itself. Each of the grids in which
the data is displayed have edit, add and delete buttons. The grids are read
only. When the add or edit button is clicked a small editkeyword or
editsearchprhase form is opened up, tied to the main form by a currency
manager.
Delete works fine. Edit works fine. But add doesn't work. So I decided to
catch errors, the edit form doesn't open up at all. Without errors it does,
but the add
doesn't work. Here's some code.
Private Sub frmFullWord_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Try
cnWKS.ConnectionString = gstrconn
cm = CType(BindingContext(dsWKS1, "KeyWordSets"), CurrencyManager)
AddHandler cm.ItemChanged, AddressOf cm_ItemChanged
AddHandler cm.PositionChanged, AddressOf cm_PositionChanged
AddHandler daWKS.RowUpdated, AddressOf OnRowUpDated
cmK = CType(BindingContext(dsWKS1,
"KeywordSets.KeywordSetsKeywords"), CurrencyManager)
cmSP = CType(BindingContext(dsWKS1,
"KeywordSets.KeywordSetsSearchPhrase"), CurrencyManager)
daWKS.Fill(dsWKS1, "KeywordSets")
Me.dsWKS1.KeywordSets.ActiveColumn.DefaultValue = True
daWK.Fill(dsWKS1, "Keywords")
daWSP.Fill(dsWKS1, "SearchPhrase")
Catch ex As OleDbException
If ex.Errors(0).SQLState = "3022" Then
MsgBox(ex.Errors(0).Message & s & "Please try again")
dsWKS1.Clear()
daWKS.Fill(dsWKS1, "KeywordSets")
daWK.Fill(dsWKS1, "Keywords")
daWSP.Fill(dsWKS1, "SearchPhrase")
Exit Try
Else
Dim errorMessages As String
Dim i As Integer = 0
errorMessages += "Index #" & i.ToString() & ControlChars.Cr _
& "Message: " & ex.Errors(i).Message &
ControlChars.Cr _
& "NativeError: " & ex.Errors(i).NativeError
& ControlChars.Cr _
& "Source: " & ex.Errors(i).Source &
ControlChars.Cr _
& "SQLState: " & ex.Errors(i).SQLState &
ControlChars.Cr _
& "StackTrace: " & ex.stacktrace &
ControlChars.Cr _
& ""
MsgBox(errorMessages)
End If
Catch ex As NullReferenceException
Exit Try
Catch ex As InvalidCastException
Exit Try
Catch ex As DBConcurrencyException
MsgBox(ex.Message & s & "The dataset will be refreshed." & s &
"Then you can navigate to the row and update it again.")
dsWKS1.Clear()
daWKS.Fill(dsWKS1, "KeywordSets")
daWK.Fill(dsWKS1, "Keywords")
daWSP.Fill(dsWKS1, "SearchPhrase")
Exit Try
Catch ex As Exception
MsgBox(ex.GetType.ToString & s & ex.Message & s & ex.HelpLink &
s & ex.StackTrace & s & ex.Source & s & "The form will be closed") '& s &
ex.TargetSite)
'Me.Close()
End Try
SetEditMode(False)
End Sub
and the add buttons for keywords ( searchphrase is similar)
Private Sub btnAddK_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnAddK.Click
If cm.Count > 0 Then
Try
cmK.AddNew()
Me.dsWKS1.Keywords.ActiveColumn.DefaultValue = True
Dim frmEditKeyword As New frmEditKeyword
With frmEditKeyword
.EditKeyword(cmK)
.KeywordSetID = Me.KSID
.txtKeywordSetID.Text = frmEditKeyword.KeywordSetID
.ShowDialog()
End With
frmEditKeyword.Dispose()
Catch ex As Exception
MsgBox(ex.GetType.ToString & s & ex.Message & s &
ex.HelpLink & s & ex.StackTrace & s & ex.Source & s & "The form will be
closed") '& s & ex.TargetSite)
Finally
End Try
Else
MessageBox.Show("No Current KeywordSet!", "Add Keyword",
MessageBoxButtons.OK, MessageBoxIcon.Error)
End If
End Sub
Here are excerpts from the error message when I click the keyword add
button:
system.invalidcastexception
object cannot be cast from dbnull to other types
...
at system.windowsforms.unsafenativemethods.intcreatewindowex
...
at fullword.vb line 967
With frmEditKeyword
.EditKeyword(cmK)
.KeywordSetID = Me.KSID
.txtKeywordSetID.Text = frmEditKeyword.KeywordSetID
.ShowDialog()
End With
line 967 is .showidialog.
The error message on add searchphrase:
...
edit fullword.vb line 991
line 156 is
line 988 is .showdialog
if i comment out the try..end try lines and show dialog, then when I
click addK or addSP I get another row in the respective grid, but can't edit
the keyword or searchphrase, because the grid is read-only.
However, the edit boxes work fine, even with the .showdialog and without the
try..endtry, etc.
can somebody help me?
dennis
Haven't been progressing on this lately because of the Holy Days in Israel
and the call of other work.
Kevin Yu has been instrumental in helping me so far.
Have a keywordset table bound to textboxes and a checkbox, with the usual
buttons for moving position, adding, deleting, updating the dataset and
updating the database through the data adapter.
All work fine.
There are two child tables, keywords and searchphrase, related in the
dataset's xsd file and in the database itself. Each of the grids in which
the data is displayed have edit, add and delete buttons. The grids are read
only. When the add or edit button is clicked a small editkeyword or
editsearchprhase form is opened up, tied to the main form by a currency
manager.
Delete works fine. Edit works fine. But add doesn't work. So I decided to
catch errors, the edit form doesn't open up at all. Without errors it does,
but the add
doesn't work. Here's some code.
Private Sub frmFullWord_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Try
cnWKS.ConnectionString = gstrconn
cm = CType(BindingContext(dsWKS1, "KeyWordSets"), CurrencyManager)
AddHandler cm.ItemChanged, AddressOf cm_ItemChanged
AddHandler cm.PositionChanged, AddressOf cm_PositionChanged
AddHandler daWKS.RowUpdated, AddressOf OnRowUpDated
cmK = CType(BindingContext(dsWKS1,
"KeywordSets.KeywordSetsKeywords"), CurrencyManager)
cmSP = CType(BindingContext(dsWKS1,
"KeywordSets.KeywordSetsSearchPhrase"), CurrencyManager)
daWKS.Fill(dsWKS1, "KeywordSets")
Me.dsWKS1.KeywordSets.ActiveColumn.DefaultValue = True
daWK.Fill(dsWKS1, "Keywords")
daWSP.Fill(dsWKS1, "SearchPhrase")
Catch ex As OleDbException
If ex.Errors(0).SQLState = "3022" Then
MsgBox(ex.Errors(0).Message & s & "Please try again")
dsWKS1.Clear()
daWKS.Fill(dsWKS1, "KeywordSets")
daWK.Fill(dsWKS1, "Keywords")
daWSP.Fill(dsWKS1, "SearchPhrase")
Exit Try
Else
Dim errorMessages As String
Dim i As Integer = 0
errorMessages += "Index #" & i.ToString() & ControlChars.Cr _
& "Message: " & ex.Errors(i).Message &
ControlChars.Cr _
& "NativeError: " & ex.Errors(i).NativeError
& ControlChars.Cr _
& "Source: " & ex.Errors(i).Source &
ControlChars.Cr _
& "SQLState: " & ex.Errors(i).SQLState &
ControlChars.Cr _
& "StackTrace: " & ex.stacktrace &
ControlChars.Cr _
& ""
MsgBox(errorMessages)
End If
Catch ex As NullReferenceException
Exit Try
Catch ex As InvalidCastException
Exit Try
Catch ex As DBConcurrencyException
MsgBox(ex.Message & s & "The dataset will be refreshed." & s &
"Then you can navigate to the row and update it again.")
dsWKS1.Clear()
daWKS.Fill(dsWKS1, "KeywordSets")
daWK.Fill(dsWKS1, "Keywords")
daWSP.Fill(dsWKS1, "SearchPhrase")
Exit Try
Catch ex As Exception
MsgBox(ex.GetType.ToString & s & ex.Message & s & ex.HelpLink &
s & ex.StackTrace & s & ex.Source & s & "The form will be closed") '& s &
ex.TargetSite)
'Me.Close()
End Try
SetEditMode(False)
End Sub
and the add buttons for keywords ( searchphrase is similar)
Private Sub btnAddK_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnAddK.Click
If cm.Count > 0 Then
Try
cmK.AddNew()
Me.dsWKS1.Keywords.ActiveColumn.DefaultValue = True
Dim frmEditKeyword As New frmEditKeyword
With frmEditKeyword
.EditKeyword(cmK)
.KeywordSetID = Me.KSID
.txtKeywordSetID.Text = frmEditKeyword.KeywordSetID
.ShowDialog()
End With
frmEditKeyword.Dispose()
Catch ex As Exception
MsgBox(ex.GetType.ToString & s & ex.Message & s &
ex.HelpLink & s & ex.StackTrace & s & ex.Source & s & "The form will be
closed") '& s & ex.TargetSite)
Finally
End Try
Else
MessageBox.Show("No Current KeywordSet!", "Add Keyword",
MessageBoxButtons.OK, MessageBoxIcon.Error)
End If
End Sub
Here are excerpts from the error message when I click the keyword add
button:
system.invalidcastexception
object cannot be cast from dbnull to other types
...
at system.windowsforms.unsafenativemethods.intcreatewindowex
...
at fullword.vb line 967
With frmEditKeyword
.EditKeyword(cmK)
.KeywordSetID = Me.KSID
.txtKeywordSetID.Text = frmEditKeyword.KeywordSetID
.ShowDialog()
End With
line 967 is .showidialog.
The error message on add searchphrase:
...
edit fullword.vb line 991
line 156 is
line 988 is .showdialog
if i comment out the try..end try lines and show dialog, then when I
click addK or addSP I get another row in the respective grid, but can't edit
the keyword or searchphrase, because the grid is read-only.
However, the edit boxes work fine, even with the .showdialog and without the
try..endtry, etc.
can somebody help me?
dennis