Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Linqdatasource - nullable decimal not udating

Status
Not open for further replies.

shaunk

Programmer
Aug 20, 2001
402
AU
I have a Listview with a LinqDataSource.
I am allocating a resoure called Bladder Scanners to clinicians on the day selected. The field in the database, 'Allocated_Bladder_Scanner_Id', is tinyint and allows nulls.
The 'nullable' property of the field in the dbml is set to allow nulls.
In the edit template, I have an unbound dropdownlist (drpBladderScannerDropdown) with an 'empty string' item added to cater for nulls, and AppendDataBoundItems="true".
In order to show only bladder scanners which have not yet been allocated on the selected day, I am databinding the dropdownlist to a dictionary of unallocated bladder scanners in the ItemDataBound event. I then add the currently selected bladder scanner as a listitem and set it as the selected item.
So far, so good, all works well.

If the user elects to unallocate the clinician a bladder scanner by selecting 'Nothing' from the dropdownlist, I send a Nullable(of Byte) field to the dbml that is set to Nothing. The problem is that it won't update the field..

In ItemUpdating I have the following code:
Code:
Dim drpBladderScannerDropdown As DropDownList = CType(ListView1.Items(e.ItemIndex).FindControl("drpBladderScannerDropdown"), DropDownList)
If drpBladderScannerDropdown.SelectedValue = String.Empty Then
      e.NewValues("Allocated_Bladder_Scanner_Id") = CType(Nothing, Nullable(Of Byte))
Else
      e.NewValues("Allocated_Bladder_Scanner_Id") = drpBladderScannerDropdown.SelectedValue
End If

I run through the dbml code in debug, but can't see how it is behaving differently to any other update.

Thanks





The risk with keeping an open mind is having your brains fall out.
Shaunk

 
tinyint isn't a byte and nothing in vs is not null on the database.
try this instead
Code:
e.NewValues("Allocated_Bladder_Scanner_Id") = DbNull.Value

Jason Meckley
Programmer

faq855-7190
faq732-7259
 
Your suggestion resulted in the following error message

Exception message: Failed to set one or more properties on type Provider_Day. Cannot convert value of parameter 'Allocated_Bladder_Scanner_Id' from 'System.DBNull' to 'Nullable'.

Just a couple of points on your comments
1. tinyint isn't a byte - VS set the property of 'Allocated_Bladder_Scanner_Id' to 'system.byte' when creating the dbml, so I suppose its the best approximation.
Why .Net and SQL Server have different datatypes is beyond me.
2. The property in the dataclass is this
Code:
  <Column(Storage:="_Allocated_Bladder_Scanner_Id", DbType:="TinyInt NULL", CanBeNull:=True, UpdateCheck:=UpdateCheck.Never)> _
Public Property Allocated_Bladder_Scanner_Id() As System.Nullable(Of Byte)
        Get
            Return Me._Allocated_Bladder_Scanner_Id
        End Get
        Set(ByVal value As System.Nullable(Of Byte))
            If (Me._Allocated_Bladder_Scanner_Id.Equals(value) = False) Then
                If Me._Lookup_Bladder_Scanner.HasLoadedOrAssignedValue Then
                    Throw New System.Data.Linq.ForeignKeyReferenceAlreadyHasValueException
                End If
                Me.OnAllocated_Bladder_Scanner_IdChanging(value)
                Me.SendPropertyChanging()
                Me._Allocated_Bladder_Scanner_Id = value
                Me.SendPropertyChanged("Allocated_Bladder_Scanner_Id")
                Me.OnAllocated_Bladder_Scanner_IdChanged()
            End If
        End Set

Thanks







The risk with keeping an open mind is having your brains fall out.
Shaunk

 
Interesting, I wouldn't have suspected that. I'm sure there is a way to get this working, but I found datasources are not worth the trouble.

I would drop them in favor of managing the data access outside of webforms. whether it's raw sql, an ORM or some other data access strategy. It will be better than DataSource controls.

Jason Meckley
Programmer

faq855-7190
faq732-7259
 
Totally agree. I'm persisting with this on one page only, to at least say I have investigated LINQ to SQL.
There's some powerful stuff you can do with it, but the actual plumbing is that far abstracted from where you can get at it, that it becomes impossible to debug in situations like this...let alone the performance hit.
If a LingDataSource is going to deal with nulls, it at least has to have row class processing generated so you can utilise Set@fieldNull e.g. SetAllocated_Bladder_Scanner_IdNull()

On to LINQ to Entities next.

Thanks for your time.

The risk with keeping an open mind is having your brains fall out.
Shaunk

 
I have investigated LINQ to SQL.
that is a dead project and wasn't that powerfull at all.
On to LINQ to Entities next.
Do you mean the Entity Framework? Now your moving in the right direction, ORM. However I would recommend NHibernate or ActiveRecord over EF.

EF is too little too late compared to NH and AR.
EF has also focused more on designers and WYSIWYG development than they have the features of the runtime.

NH and AR have a longer learning curve, but the pay off is much greater and the frameworks have more features then EF.

Jason Meckley
Programmer

faq855-7190
faq732-7259
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top