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. General Programming
  3. C#
  4. DataView Problem

DataView Problem

Scheduled Pinned Locked Moved C#
helpdatabase
2 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.
  • M Offline
    M Offline
    Michael101
    wrote on last edited by
    #1

    I have a dataview..... When it retrieves data from the database there is a column in my data base that stores 1's and 2's. 1's mean 'Yes' and 2's mean 'No'. This column (St_Assess_Ev_Checked) has been declared as an Integer. How do you iterate through a dataview, if it see's 1 it prints yes to my datagrid and if it see's 2 it prints no. This is my code so far.... hope I'm at least close. DataSet sqlDS = new DataSet(); SqlDataAdapter sqlDA = new SqlDataAdapter(stReport, sqlConnection); sqlDA.Fill(sqlDS, "progReport"); dv = sqlDS.Tables["progReport"].DefaultView; IEnumerator iterator = dv.GetEnumerator(); foreach(DataRowView drv2 in dv) { for (int x = 0; x < dv.Count; x++) { if(dv[0]["St_Assess_Ev_Checked"].ToString() == "1") { dv.AllowEdit = true; dv[0].BeginEdit(); dv[0]["St_Assess_Ev_Checked"] = "Yes"; dv[0].EndEdit(); } else { Response.Write(dv[x].ToString()); } } } You could of guessed the error.... Cannot convert types expected Int32! Thanks in advance, appeciate it! :)

    S 1 Reply Last reply
    0
    • M Michael101

      I have a dataview..... When it retrieves data from the database there is a column in my data base that stores 1's and 2's. 1's mean 'Yes' and 2's mean 'No'. This column (St_Assess_Ev_Checked) has been declared as an Integer. How do you iterate through a dataview, if it see's 1 it prints yes to my datagrid and if it see's 2 it prints no. This is my code so far.... hope I'm at least close. DataSet sqlDS = new DataSet(); SqlDataAdapter sqlDA = new SqlDataAdapter(stReport, sqlConnection); sqlDA.Fill(sqlDS, "progReport"); dv = sqlDS.Tables["progReport"].DefaultView; IEnumerator iterator = dv.GetEnumerator(); foreach(DataRowView drv2 in dv) { for (int x = 0; x < dv.Count; x++) { if(dv[0]["St_Assess_Ev_Checked"].ToString() == "1") { dv.AllowEdit = true; dv[0].BeginEdit(); dv[0]["St_Assess_Ev_Checked"] = "Yes"; dv[0].EndEdit(); } else { Response.Write(dv[x].ToString()); } } } You could of guessed the error.... Cannot convert types expected Int32! Thanks in advance, appeciate it! :)

      S Offline
      S Offline
      SimulationofSai
      wrote on last edited by
      #2

      Do it in your datagrid ItemDataBound event. This should help you. SG

      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