query nullable colunn will always get null
-
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)
-
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)
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
-
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
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 ispublic 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?