---
title: "System.InvalidCastException: Specified cast is not valid"
type: "forum-thread"
url: "https://www.webforum.nu/amne/dotnet/68729-system-invalidcastexception-specified-cast-is-not-valid"
topic: ".NET"
topic_url: "https://www.webforum.nu/amne/dotnet"
author: "andreas_lindh"
published: "2003-02-19T10:56:13.000Z"
updated: "2003-02-19T14:06:33.000Z"
replies: 4
views: 234
page: 1
pages: 1
language: "sv-SE"
site: "webForum — webforum.nu"
rights: "Upphovsrätten till varje inlägg tillhör dess författare."
attribution: "Citera som: webForum, https://www.webforum.nu/amne/dotnet/68729-system-invalidcastexception-specified-cast-is-not-valid"
---

# System.InvalidCastException: Specified cast is not valid

## #1 — andreas_lindh, 2003-02-19T10:56Z

Försöker fylla en datalist med den här koden

```
Dim objconn As New OleDbConnection(ConfigurationSettings.AppSettings("connectionstring"))
    Public dl_poll As DataList
    Public error6 As Label
    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        If Not (IsPostBack) Then
            bindgrid()
        End If
    End Sub

    Private grupp As String = ""
    Public Property _pid() As String
        Get
            grupp = grupp
        End Get
        Set(ByVal Value As String)
            grupp = Value
        End Set
    End Property

    Public Sub bindgrid()

        Dim objcmd As New OleDbDataAdapter _
            ("select [id],[votes],[pid],[alternativ] from [votes] where [pid]=" & grupp & " order by [id] desc", objconn)

        Dim ds1 As DataSet = New DataSet()
        objcmd.Fill(ds1, "poll1")

        dl_poll.DataSource = ds1.Tables("poll1"). _
        DefaultView
        DataBind()
    End Sub
```

Får det här felmeddelandet

```
Source Error: 

Line 49:         dl_poll.DataSource = ds1.Tables("poll1"). _
Line 50:         DefaultView
Line 51:         DataBind()
Line 52:     End Sub
Line 53: 
 

Source File: h:\inetpub\wwwroot\tibroik.net\poll.ascx.vb    Line: 51
```

Någon som vet vad som kan vara fel?

Permalänk: https://www.webforum.nu/p/68729

## #2 — cyprys, 2003-02-19T12:49Z

dl_poll.databind()

Permalänk: https://www.webforum.nu/p/957096

## #3 — andreas_lindh, 2003-02-19T13:13Z

har redan provat det och det ger samma fel

Permalänk: https://www.webforum.nu/p/957109

## #4 — cyprys, 2003-02-19T13:50Z

Detta funkar alltså inte?

```
dl_poll.DataSource = ds1.Tables("poll1").DefaultView
dl_poll.DataBind()
```

Permalänk: https://www.webforum.nu/p/957136

## #5 — andreas_lindh, 2003-02-19T14:06Z

nej.

Permalänk: https://www.webforum.nu/p/957151

---

Tråden på webben: https://www.webforum.nu/amne/dotnet/68729-system-invalidcastexception-specified-cast-is-not-valid
