Has anyone ever had a problem DataBinding to this field type I have a method that sets up all my DataBindings for my controls on the form and when I run it I get this error: "DataBinding could not find a row in the list that is suitable for all bindings"
When I comment out the DataBindings for the fields that are pulling from fields of type money, it works just fine.
Is this a bug or is it possible that I did something wrong

DataBinding to a SQL Field of type money
Richard Masse
briankerri
Jason
Omen
Check out my other post complaining about this error that I posted yesterday: <a href="http://www.windowsforms.net/Forums/ShowPost.aspx tabIndex=1&tabId=41&PostID=1071">BindingManagerBase.ResumeBinding()</a>
The error is totally lame if you ask me...doesn't tell me anything...I just had to start commenting out lines until I found that it was all the money fields that were giving the error!
I guess I'll hit up google now :(
dfl
Sverk
so now this is where I get desperate and start pasting code like a mad man!
'add the bindings to a control
Private Sub AddFieldBinding(ByRef Control As Control, ByVal PropertyName As String, ByVal DataTableName As String, ByVal FieldName As String, ByVal AddHandlers As Boolean)
Dim Binding As Binding = Control.DataBindings.Add(PropertyName, Data, DataTableName & "." & FieldName)
If AddHandlers Then
With Binding
AddHandler .Parse, AddressOf BindingParser
AddHandler .Format, AddressOf BindingFormatter
End With
End If
End Sub
'remove the bindings from a control
Private Sub RemoveFieldBinding(ByRef Control As Control, ByVal PropertyName As String, ByVal RemoveHandlers As Boolean)
If Not Control.DataBindings(PropertyName) Is Nothing Then
If RemoveHandlers Then
With Control.DataBindings(PropertyName)
RemoveHandler .Parse, AddressOf BindingParser
RemoveHandler .Format, AddressOf BindingFormatter
End With
End If
Control.DataBindings.Remove(Control.DataBindings.Item(PropertyName))
End If
End Sub
'Format Event Handler
Private Sub BindingFormatter(ByVal sender As Object, ByVal e As ConvertEventArgs)
If e.DesiredType Is GetType(Boolean) Then
e.Value = Utilities.Global.NullToBoolean(e.Value)
End If
If e.DesiredType Is GetType(String) Then
e.Value = Utilities.Global.NullToEmpty(e.Value)
End If
If e.DesiredType Is GetType(Decimal) Then
e.Value = CType(e.Value, Decimal).ToString("c")
End If
End Sub
'Parse Event Handler
Private Sub BindingParser(ByVal sender As Object, ByVal e As ConvertEventArgs)
If e.DesiredType Is GetType(String) AndAlso e.Value = "" Then
e.Value = Utilities.Global.EmptyToNull(e.Value)
End If
If e.DesiredType Is GetType(Decimal) Then
e.Value = Decimal.Parse(e.Value.ToString, Globalization.NumberStyles.Currency)
End If
End Sub
'this is the sub that gives the error on the line where the try catch is
'and it's because of the 4 lines after the 'error comment line
'the field types for all 4 are of sql type money
Private Sub SetupFieldBindings()
Me.BindingContext(Data, "tblBusiness").SuspendBinding()
AddFieldBinding(txtSolomonBusinessId, "Text", "tblBusiness", "SolomonBusinessId", False)
AddFieldBinding(txtBusinessName, "Text", "tblBusiness", "BusinessName", True)
AddFieldBinding(cboBusinessType, "SelectedItem", "tblBusiness", "BusinessType", True)
AddFieldBinding(cboBusinessStatus, "SelectedItem", "tblBusiness", "BusinessStatus", True)
AddFieldBinding(chkCustomerFlag, "Checked", "tblBusiness", "CustomerFlag", True)
AddFieldBinding(chkCarrierFlag, "Checked", "tblBusiness", "CarrierFlag", True)
AddFieldBinding(chkWarehouseFlag, "Checked", "tblBusiness", "WarehouseFlag", True)
AddFieldBinding(chkVendorFlag, "Checked", "tblBusiness", "VendorFlag", True)
AddFieldBinding(txtComments, "Text", "tblBusiness", "Comments", True)
AddFieldBinding(chkFirstMonthStorageFlag, "Checked", "tblBusiness", "FirstMonthStorageFlag", True)
'error
MessageBox.Show(Data.Tables("tblBusiness").Rows(0).Item("StorageInOut"))
AddFieldBinding(txtStorageInOut, "Text", "tblBusiness", "StorageInOut", True)
AddFieldBinding(txtStorageTransfer, "Text", "tblBusiness", "StorageTransfer", True)
AddFieldBinding(txtStorageMonthlyCoil, "Text", "tblBusiness", "StorageMonthlyCoil", True)
AddFieldBinding(txtStorageFinishedGoods, "Text", "tblBusiness", "StorageFinishedGoods", True)
AddFieldBinding(txtMailingAddress1, "Text", "tblBusiness", "MailingAddress1", True)
AddFieldBinding(txtMailingAddress2, "Text", "tblBusiness", "MailingAddress2", True)
AddFieldBinding(txtMailingCity, "Text", "tblBusiness", "MailingCity", True)
AddFieldBinding(txtMailingState, "Text", "tblBusiness", "MailingState", True)
AddFieldBinding(txtMailingCountry, "Text", "tblBusiness", "MailingCountry", True)
AddFieldBinding(txtMailingPhoneNumber, "Text", "tblBusiness", "MailingPhoneNumber", True)
AddFieldBinding(txtMailingExtension, "Text", "tblBusiness", "MailingExtension", True)
AddFieldBinding(txtMailingFaxNumber, "Text", "tblBusiness", "MailingFaxNumber", True)
AddFieldBinding(txtMailingWebsite, "Text", "tblBusiness", "MailingWebsite", True)
'terms
AddFieldBinding(txtPhysicalAddress1, "Text", "tblBusiness", "PhysicalAddress1", True)
AddFieldBinding(txtPhysicalAddress2, "Text", "tblBusiness", "PhysicalAddress2", True)
AddFieldBinding(txtPhysicalCity, "Text", "tblBusiness", "PhysicalCity", True)
AddFieldBinding(txtPhysicalState, "Text", "tblBusiness", "PhysicalState", True)
AddFieldBinding(txtPhysicalCountry, "Text", "tblBusiness", "PhysicalCountry", True)
AddFieldBinding(txtPhysicalPhone, "Text", "tblBusiness", "PhysicalPhone", True)
AddFieldBinding(txtPhysicalFaxNumber, "Text", "tblBusiness", "PhysicalFaxNumber", True)
Try
Me.BindingContext(Data, "tblBusiness").ResumeBinding()
Catch Ex As Exception
Utilities.Prompt.ShowError(Ex.ToString)
End Try
End Sub
deepakleo2003
I have seen that message before if the table is empty or if a particular field does not have a default value. Set the default value to $0.00.
Jason
fictionforever
I sort of understand the problem, because a money field is translated to the native Decimal type and Decimals can not ever be Nothing, where as a String can, but even with values in those money fields, the Binding still doesn't work :( And as I mentioned before, the values that are coming in for the money fields are all "0"
:@ grrrr
markvanh
Jason
Kakurady
Bradster