Delete Record

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • shapper

    #1

    Delete Record

    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.ItemTemp late = New MyItemTemplate( )
    lvTags.LayoutTe mplate = New MyLayoutTemplat e()
    End Sub

    Private Sub lv_Load(ByVal sender As Object, ByVal e As EventArgs)
    Handles lv.Load
    Dim database As New MyContextDataCo ntext
    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
    ListViewDeleteE ventArgs) Handles lv.ItemDeleting
    Dim database As New MyContextDataCo ntext
    Dim tags = From t In database.Tags _
    Where t.TagID = New
    Guid(lvTags.Dat aKeys(e.ItemInd ex).Value.ToStr ing)
    database.Tags.R emove(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.Li nq.DataQuery`1[Undefined.Data. Linq.Tag]' to type
    'Undefined.Data .Linq.Tag'

    What am I doing wrong?

    Thanks,
    Miguel
  • Cor Ligthert[MVP]

    #2
    Re: Delete Record

    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.Dat aKeys(e.ItemInd ex).Value.ToStr ing)


    Cor

    "
    Dim tags = From t In database.Tags _
    Where t.TagID = New
    Guid(lvTags.Dat aKeys(e.ItemInd ex).Value.ToStr ing)
    database.Tags.R emove(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.Li nq.DataQuery`1[Undefined.Data. Linq.Tag]' to type
    'Undefined.Data .Linq.Tag'
    >
    What am I doing wrong?
    >
    Thanks,
    Miguel

    Comment

    • shapper

      #3
      Re: Delete Record

      On Dec 5, 4:55 am, "Cor Ligthert[MVP]" <notmyfirstn... @planet.nl>
      wrote:
      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.Dat aKeys(e.ItemInd ex).Value.ToStr ing)
      >
      Cor
      >
      "
      >
      Dim tags = From t In database.Tags _
      Where t.TagID = New
      Guid(lvTags.Dat aKeys(e.ItemInd ex).Value.ToStr ing)
      database.Tags.R emove(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.Li nq.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.Submit Changes()

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

      Thanks,
      Miguel

      Comment

      Working...