ok I have a weird issue. I created a master record in the master table and then a record in the detail table. when creating the detail record i get a Specified cast is not valid error. Now another weird thing is that once I create the master record I can't query and verify it was created. But when i got to sql management studio I can see the master record. Below is my two procedures and the table definitions. Master table primary key is INVNUM child table primary key it INVLIN_ID and the reference key is INVNUM
Code:Partial Public Class RcvMaster Implements System.ComponentModel.INotifyPropertyChanging, System.ComponentModel.INotifyPropertyChanged Private Shared emptyChangingEventArgs As PropertyChangingEventArgs = New PropertyChangingEventArgs(String.Empty) Private _INVNUM As String Private _invtyp As String Private _invdte As System.Nullable(Of Date) Private _expdte As System.Nullable(Of Date) Private _invsts As String Private _rcvcont As String Private _rcvdte As System.Nullable(Of Date) Private _credte As System.Nullable(Of Date) Private _RcvDetails As EntitySet(Of RcvDetail)Insert master belowCode:<Global.System.Data.Linq.Mapping.TableAttribute(Name:="dbo.RcvDetail")> _ Partial Public Class RcvDetail Implements System.ComponentModel.INotifyPropertyChanging, System.ComponentModel.INotifyPropertyChanged Private Shared emptyChangingEventArgs As PropertyChangingEventArgs = New PropertyChangingEventArgs(String.Empty) Private _INVLIN_ID As Integer Private _INVNUM As String Private _prtnum As String Private _linnum As System.Nullable(Of Integer) Private _expqty As System.Nullable(Of Integer) Private _rcvqty As System.Nullable(Of Integer) Private _exprdte As System.Nullable(Of Date) Private _lotnum As String Private _RcvMaster As EntityRef(Of RcvMaster)
Is detailsCode:If VerifyFields(False) Then If IsMasterCreated = True Then MessagePresenter.ShowMessage("You cannot create two master records complete the first one", "Master Already Exist for this receipt") Else Dim NewMasterRecord = New RcvMaster With {.expdte = ExpectedDateTimeEditor.Value, .invdte = InvoiceDateTimeEditor.Value, .INVNUM = CurrentInvoiceNumber, .rcvcont = ContainerTextBox.Text} db.RcvMasters.InsertOnSubmit(NewMasterRecord) Try db.SubmitChanges() IsMasterCreated = True InvoiceNumberTextBox.IsEnabled = False ContainerTextBox.IsEnabled = False MessagePresenter.ShowMessage("Master Created", "Master Created") Catch ex As Exception MessagePresenter.ShowMessage(ex.Message, "Exception Error") End Try End If Else MessagePresenter.ShowMessage("Please complete all fields", "Missing Information") End If
Code:If VerifyLineItem() Then If IsMasterCreated Then Dim ExpireDate As Date = ExpectedDateTimeEditor.Value If ExpireDate = Nothing Then ExpireDate = Date.Now End If Dim check = (From I In db.RcvMasters Where I.INVNUM = Trim(CurrentInvoiceNumber) Select I.invsts).First Dim NewLineItemRecord As New RcvDetail With {.INVNUM = CurrentInvoiceNumber, .expqty = CType(ExpectedQtyTextBox.Text, Integer), .lotnum = LotNumberTextBox.Text, .prtnum = PartNumberComboBox.SelectedValue.ToString, .exprdte = ExpireDate, .linnum = LineCount } db.RcvDetails.InsertOnSubmit(NewLineItemRecord) Try db.SubmitChanges() IsCurrentlyWorking = True RefreshGrid() LineCount += 1 Catch ex As Exception MessagePresenter.ShowMessage(ex.Message, "Exception Error") End Try Else MessagePresenter.ShowMessage("Please create master invoice first", "Master invoice not created") End If End If




Reply With Quote