Datatable internal index is corrupted ‘5’ – on Dataset save

See  http://support.microsoft.com/kb/932491

Issue 5: When a Merge operation occurs, the record manager may become corrupted if the target row is in the edit state

I got this when i was repeatedly updating totals in databound text boxes from Detail rows into the Header table on every move or listchanged. Then bindingsource.addnew, then fill in data, then try and save giving error:- Datatable internal index is corrupted ‘5’

Solutions included:

  1. Remove data binding to text boxes. Write these when updating totals.
  2. Write totals to HeaderRow only if saving
  3. Also found that GetTotals was being called 3 times, on list clear, on parent bindingsource move, on fill detail.
    Controlled this better by putting a SuspendRefreshFlag, before LoadDetail, then after load, GetTotal, Then SuspendRefreshFlag = False again.
  4. Also in ListChanged event use the ByVal e As System.ComponentModel.ListChangedEventArgs

If e.ListChangedType <> System.ComponentModel.ListChangedType.Reset Then
   GetSumFromDetail()
End If

Occurrences

  1. First occurrence at first writing of this post
  2. frmInvoiceDetail – Dec 2012
    • was in ListChanged

 

 

Dataset TableAdapter CommandTimeout

If get error:
“Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding”

Setting the connection string timeout does not work.

Following links led me to my own visual basic translation. I found i had to add the check for the commandCollection Is Nothing
http://www.velocityreviews.com/forums/t123478-how-to-set-commandtimeout-for-getdata-method-of-tableadapter-asp-net-2-0-a.html
http://www.pcreview.co.uk/forums/tableadapter-and-commandtimeout-t2354775.html

Because the DatasetName.Designer.vb is a partial class, it is possible to create a second partial class which will not be overwritten on changes to the dataset. Remember to use

Namespace xxxTableAdapters

    Partial Public Class xxxTableAdapter

        Public WriteOnly Property SetSelectCommandTimeout() As Integer
            Set(ByVal value As Integer)
                If Me._commandCollection Is Nothing Then
                    Me.InitCommandCollection()
                End If
                Me.CommandCollection(0).CommandTimeout = value
                ‘For Each cmd In Me._commandCollection  ‘To do all
                ‘    cmd.CommandTimeout = value
                ‘Next
            End Set
        End Property

    End Class

End Namespace

Code Generation and T4 Text Templates

http://msdn.microsoft.com/en-us/library/bb126445.aspx

http://brochure.jrcs3.com/2011/03/t4-template-tour-of-first-gear.html

Include directive

Quite useful
<#@ include file=”TextTemplateVB6.t4″ #>
<#@ include File=”$(SolutionDir)\CodeDBGenerator\TextTemplateLibrary\TextTemplate\GeneratedHeader.t4″ #>

This uses actual file location, which may be different to how it appears in Solution explorer.

Note: the included file cannot have a <#@ template language=”VB” #> on it.
Probably want to rename it .t4 and remove the custom tool, so that it does not generate it’s own file.
After it has been included then Class Feature Blocks may be put in here for re-use by many templates. <#+

If you want it separately and also included elsewhere then a strategy I came up with was to have have the file without the <#@ template language=”VB” #> and then a separate file which was just:

<#@ template language=”VB” #>
<#@ include file=”TextTemplateVB6.t4″ #>
Be careful on .t4 file, you probably want to not have a custom tool. This can be done by creating a standard text file and changing it’s file extenstion to .t4 or create a text template file and then remove the Custom Tool from files properties. See:  Run Custom Tool

 

To use T4 within a program

To have a form that generates code say in a text box. Then:

  1. Set “Custom Tool” of text template to “TextTemplatingFilePreprocessor” and Custom Tool Namespace to say “My.Templates”
  2. Dim code = New My.Templates.PreTextTemplate1
    GeneratedCodeTextBox.Text = code.TransformText

 

To use If.

For instance with include file then:

<# If ParameterList(4) = 1 Then #>
<#@ include file=”SetRowBase.tt” #>
<# End If #>

 

More blog TODO

… looks potentially useful in some circumstances

Directives
http://msdn.microsoft.com/en-us/library/bb126421.aspx

To read
http://msdn.microsoft.com/en-us/library/gg251243.aspx

Run Custom Tool

Solution Folder > Point at file > Right click Properties
Custom Tool – Add or remove a custom tool name here.

Examples

  • TextTemplatingFileGenerator
  • TextTemplatingFilePreprocessor

‘Settings’ is not a member of ‘My’

SOLVED

Try adding the namespace, so:

My.Settings.conAName
becomes
[Namespace].Settings.conAName

How do I … work with Guid in ADO.Net?

How do I … work with Guid in ADO.Net?
( in this case to support SQL Server replication using dataset )

26-Dec-2011
Hypothesis: That DataSet could act unaware of replication column (do not import it on datatable creation) (or delete it after). Then use default in SQL Server (newsequentialid())
Experiment: Worked out of the box – straight away

During creation of SQL Replication, SQL Server will add a rowGuid column which is a uniqueidentifier and places a default of (newsequentialid()) onto this column
Insert statements for replication must include all columns, except the rowGuid column.

ERROR
However if you then add a new row to this table in ADO.Net then program will give error message ‘Column rowGuid does not allow nulls’

SOLUTION
[MyDataTable].rowguidColumn.DefaultValue = Guid.NewGuid

EXPLANATION
SQL will have inserted a Unique index on rowGuid. However when the table is dropped onto the dataset the unique key is not there. Therefore although the above default set once will give each new row the same Guid, the ADO.net sees no errors. Because the insert statement does not insert the Guid, SQL does, then ADO.Net immediately returns the correct newly applied Guid from the database. This is because the Dataset insert statement also has a SELECT statement on it to get table updates immediately after the INSERT.

SQL Server Replication

Updating ERROR
Updating columns with the rowguidcol property is not allowed.
The transaction ended in the trigger. The batch has been aborted.

Removed the rowguid column from the dataset update sql and it worked. Found no online instruction for this in short search.

Cannot bind to the property or column .. on the datasource.

VB.Net Window Forms databinding

Cannot bind to the property or column .. on the datasource.
Parameter name: dataMember

  1. Check to see if you have used the same binding source for two or more combo boxes.
  2. or alternatively because dataMember is not strongly typed, possible that the name of a field has changed in the data set, but not in the form

Parent and Child new row on windows forms details

Problem is that
Me.ParentBindingSource.AddNew
Me.ChildBindingSource.AddNew

then when saving:
Me.ParentBindingSource.EndEdit
will destroy child row.

My workaround is:
Store a variable stating is NewRow and/or child row data IsMissing
Then on SaveData use:
If NewRow OrElse IsChildRowMissing Then
  StoreData
End If
Me.ParentBindingSource.EndEdit
If NewRow OrElse IsChildRowMissing Then
  Using taP as New dsTableAdapters.ParentTableAdapter
     taP.Update(ds)
  End Using
  DisplayStoredData – which includes re-adding child row
End If
Continue with normal save

This link describes problem but is not much help to solution:
http://www.vbdotnetforums.com/database-general-discussion/13058-calling-endedit-causes-datarelations-fail.html

..Row cannot be cast to ..Row when appear to be same. InvalidCastException

rowTS = CType(TimeSheetBindingSource.Current, DataRowView.Row, dsMyCo.TimeSheetRow

A first chance exception of type ‘System.InvalidCastException’ occurred in MyCompany.exe

[A]TimeSheetRow cannot be cast to [B]TimeSheetRow. Type A originates from ‘ProjectName, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null’ in the context ‘Default’ at location ‘Project…\bin\Debug\ProjectName.exe’. Type B originates from ‘ProjectName, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null’ in the context ‘Default’ at location Project…\bin\Debug\ProjectName.exe’.

Check you are converting from Rows in the same dataset. So if a table appears in more than one dataset check you are using the correct one.

form.designer.vb InitializeComponent bug deleting remaining controls

At top of frm.designer.vb there is following code.
If get really stuck then rem out System.Diagnostics…. and put a breakpoint here
You may want a try catch block around code that opens the form