Delete Record

  • Thread starter Thread starter shapper
  • Start date Start date
S

shapper

Hello,

I have a ListView defined as follows:

Private Sub lv_Init(ByVal sender As Object, ByVal e As EventArgs)
Handles lv.Init
lv.DataKeyNames = New String() {"TagID"}
lv.ID = "lv"
lvTags.ItemTemplate = New MyItemTemplate()
lvTags.LayoutTemplate = New MyLayoutTemplate()
End Sub

Private Sub lv_Load(ByVal sender As Object, ByVal e As EventArgs)
Handles lv.Load
Dim database As New MyContextDataContext
Dim tags = From t In database.Tags _
Select t.TagID, t.Text
lv.DataSource = tags
lv.DataBind()
End Sub

Private Sub lv_ItemDeleting(ByVal sender As Object, ByVal e As
ListViewDeleteEventArgs) Handles lv.ItemDeleting
Dim database As New MyContextDataContext
Dim tags = From t In database.Tags _
Where t.TagID = New
Guid(lvTags.DataKeys(e.ItemIndex).Value.ToString)
database.Tags.Remove(tags)
End Sub

The ListView displays all records and the ItemDeleting event is fired
but I get an error:
Unable to cast object of type
'System.Data.Linq.DataQuery`1[Undefined.Data.Linq.Tag]' to type
'Undefined.Data.Linq.Tag'

What am I doing wrong?

Thanks,
Miguel
 
shapper,

As you have this kind of problems, why then not find it yourself by
splitting the sentence in more parts to find the problem.

New Guid(lvTags.DataKeys(e.ItemIndex).Value.ToString)


Cor

"
 
shapper,

As you have this kind of problems, why then not find it yourself by
splitting the sentence in more parts to find the problem.

New Guid(lvTags.DataKeys(e.ItemIndex).Value.ToString)

Cor

"
Dim tags = From t In database.Tags _
Where t.TagID = New
Guid(lvTags.DataKeys(e.ItemIndex).Value.ToString)
database.Tags.Remove(tags)
End Sub
The ListView displays all records and the ItemDeleting event is fired
but I get an error:
Unable to cast object of type
'System.Data.Linq.DataQuery`1[Undefined.Data.Linq.Tag]' to type
'Undefined.Data.Linq.Tag'
What am I doing wrong?
Thanks,
Miguel

I found the problem. Everything was working just fine.
However, because it was not working I started to make changes to try
to find the problem and I got a few errors.

The solution to the problem, was as always, simpler then expected.

I missed:
database.SubmitChanges()

I didn't know it was need this command at the end.

Thanks,
Miguel
 
Back
Top