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. Database & SysAdmin
  3. Database
  4. query nullable colunn will always get null

query nullable colunn will always get null

Scheduled Pinned Locked Moved Database
databasehelpquestion
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.
  • J Offline
    J Offline
    JabraJabra
    wrote on last edited by
    #1

    hi, i got this table - Employees: Id | Name ------------------ 1 Avi 2 jack 3 NULL 4 NULL 5 betty when i query this sql - "select id, name from employees" i get back a data set with 5 results. the problem is that its seems like when the query executed , when the query bump into a null value in the Name column, from now on all the results will be null. it means that the dataset result will be - Id | Name ------------------ 1 Avi 2 jack 3 NULL 4 NULL 5 NULL // SUPPOSE TO BE WITH "betty" why is that? (i accord to the problem when i tried to do ds.tables[0].rows[1][4] and it returned dbnull)

    C 1 Reply Last reply
    0
    • J JabraJabra

      hi, i got this table - Employees: Id | Name ------------------ 1 Avi 2 jack 3 NULL 4 NULL 5 betty when i query this sql - "select id, name from employees" i get back a data set with 5 results. the problem is that its seems like when the query executed , when the query bump into a null value in the Name column, from now on all the results will be null. it means that the dataset result will be - Id | Name ------------------ 1 Avi 2 jack 3 NULL 4 NULL 5 NULL // SUPPOSE TO BE WITH "betty" why is that? (i accord to the problem when i tried to do ds.tables[0].rows[1][4] and it returned dbnull)

      C Offline
      C Offline
      Colin Angus Mackay
      wrote on last edited by
      #2

      Avi Laviad wrote: (i accord to the problem when i tried to do ds.tables[0].rows[1][4] and it returned dbnull) Given the SQL you gave, then this should fail. What you are saying in this piece of code is that you want the value from table[0] (the first table returned), Rows[1] (the second row, which should contain 2, Jack) and then column[4] (the fifth column is way outside the range - You should get an IndexOutOfRange exception if you run it) Perhaps, for brevity, you cut too much out of the code and we cannot see the problem anymore.


      Do you want to know more? WDevs.com - The worlds first Developers Services Provider

      J 1 Reply Last reply
      0
      • C Colin Angus Mackay

        Avi Laviad wrote: (i accord to the problem when i tried to do ds.tables[0].rows[1][4] and it returned dbnull) Given the SQL you gave, then this should fail. What you are saying in this piece of code is that you want the value from table[0] (the first table returned), Rows[1] (the second row, which should contain 2, Jack) and then column[4] (the fifth column is way outside the range - You should get an IndexOutOfRange exception if you run it) Perhaps, for brevity, you cut too much out of the code and we cannot see the problem anymore.


        Do you want to know more? WDevs.com - The worlds first Developers Services Provider

        J Offline
        J Offline
        JabraJabra
        wrote on last edited by
        #3

        i ment ds.tables[0].rows[4][1] - thats return me dbnull. my code is - DataSet ds = DBHelper.Retrieve("select TreeId, owner, Root, BranchTitle, BranchText, LeafText, ScreenShot, Leaf_ScreenShot from Trees"); ArrayList list = new ArrayList(); if (ds.Tables[0].Rows.Count > 0) { for (int i=0; i < ds.Tables[0].Rows.Count; i++) { Tree t = new Tree(); if (ds.Tables[0].Rows[i][1] == DBNull.Value) { t.Owner = 0; } else { t.Owner = (double)ds.Tables[0].Rows[i][1]; } list.Add(t); } } else { throw new Exception("No rows found"); } return list; and DBHelpr.Retrieve code is public static DataSet Retrieve(string Sql) { DBFactory db = DBFactory.Instance; // getting db factory object IDbConnection conn = db.connect(Constants.ConnStr); // connecting to db IDbDataAdapter adapter = db.getAdapter(Sql, conn); DataSet ds = new DataSet(); adapter.Fill(ds); // querying data and filling dataset db.disconnect(ref conn); // disconnecting from db return ds; } any hint?

        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