Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Help binding my datagrid Nulls error

Help binding my datagrid Nulls error

Scheduled Pinned Locked Moved ASP.NET
helpwpfwcfquestion
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    robmays
    wrote on last edited by
    #1

    Where am i going wrong? i get this error "Object cannot be cast from DBNull to other types." code private void SetFilter(string strFilterExpression) { DataRow[] foundRows; DataTable table; try { table = dst.Tables["LeadsByRegion"]; foundRows = table.Select(strFilterExpression); table.Rows.Clear(); for (int i = 0 ; i <= foundRows.GetUpperBound(0); i++) { table.NewRow(); table.Rows.Add(foundRows[i]); } this.Panel1.Visible = false; this.Panel2.Visible = true; this.dtgFiltered.DataSource = table.DefaultView; this.dtgFiltered.DataBind(); } catch (Exception ex) { this.lblError.Text = ex.Message; } }:^)

    M 1 Reply Last reply
    0
    • R robmays

      Where am i going wrong? i get this error "Object cannot be cast from DBNull to other types." code private void SetFilter(string strFilterExpression) { DataRow[] foundRows; DataTable table; try { table = dst.Tables["LeadsByRegion"]; foundRows = table.Select(strFilterExpression); table.Rows.Clear(); for (int i = 0 ; i <= foundRows.GetUpperBound(0); i++) { table.NewRow(); table.Rows.Add(foundRows[i]); } this.Panel1.Visible = false; this.Panel2.Visible = true; this.dtgFiltered.DataSource = table.DefaultView; this.dtgFiltered.DataBind(); } catch (Exception ex) { this.lblError.Text = ex.Message; } }:^)

      M Offline
      M Offline
      minhpc_bk
      wrote on last edited by
      #2

      Hi there, IMO, you can debug your application to quickly figure out which method/code causes the casting error. I guess the DataBind method, if this is the case, you might want to use the template column in the datagrid so that you can use the data binding expression to do a checking on the data before binding it to the control.

      R 1 Reply Last reply
      0
      • M minhpc_bk

        Hi there, IMO, you can debug your application to quickly figure out which method/code causes the casting error. I guess the DataBind method, if this is the case, you might want to use the template column in the datagrid so that you can use the data binding expression to do a checking on the data before binding it to the control.

        R Offline
        R Offline
        robmays
        wrote on last edited by
        #3

        many thanks for the response, It was my code was fooling me into thinking it had found records but in fact none were there, I used the DataTable.Select method instead.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups