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. Setting value for datarow if its null [modified]

Setting value for datarow if its null [modified]

Scheduled Pinned Locked Moved ASP.NET
sharepointdatabasehelp
8 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.
  • K Offline
    K Offline
    kishorgh
    wrote on last edited by
    #1

    i have datatable in which 2 row,1st column value is null that column is datatype is DateTime. wwhen i tried to add data to database..its gives me error as Object cannot be cast from DBNull to other types. i have done following.. foreach (DataRow dtRow in dtTrackingData.Rows) { SqlHelper.ExecuteNonQuery ( myConnectionString , "SP_NAME" , iWeekNo , Convert.ToInt32(dtRow["InvCoID"]) , Convert.ToDateTime(dtRow["LatestReportDateConsensus"]) , Convert.ToDateTime(dtRow["LatestReportDateVirtua"]) ,dtFromDate ,dtToDate ,CreatedBy ); } i tried to add if (dtRow["LatestReportDateConsensus"] == System.DBNull.Value) dtRow["LatestReportDateConsensus"] =null; still its not work..:( how i will add value to datarow if its null

    modified on Wednesday, June 3, 2009 1:22 AM

    K 1 Reply Last reply
    0
    • K kishorgh

      i have datatable in which 2 row,1st column value is null that column is datatype is DateTime. wwhen i tried to add data to database..its gives me error as Object cannot be cast from DBNull to other types. i have done following.. foreach (DataRow dtRow in dtTrackingData.Rows) { SqlHelper.ExecuteNonQuery ( myConnectionString , "SP_NAME" , iWeekNo , Convert.ToInt32(dtRow["InvCoID"]) , Convert.ToDateTime(dtRow["LatestReportDateConsensus"]) , Convert.ToDateTime(dtRow["LatestReportDateVirtua"]) ,dtFromDate ,dtToDate ,CreatedBy ); } i tried to add if (dtRow["LatestReportDateConsensus"] == System.DBNull.Value) dtRow["LatestReportDateConsensus"] =null; still its not work..:( how i will add value to datarow if its null

      modified on Wednesday, June 3, 2009 1:22 AM

      K Offline
      K Offline
      Kapil Thakur
      wrote on last edited by
      #2

      try using the following code : foreach (DataRow dtRow in dtTrackingData.Rows) { SqlHelper.ExecuteNonQuery ( myConnectionString , "SP_NAME" , iWeekNo , Convert.ToInt32(dtRow["InvCoID"]) , IIF(IsDBNull(dtRow["LatestReportDateConsensus"]), "null" , dtRow["LatestReportDateConsensus"] ) , Convert.ToDateTime(dtRow["LatestReportDateVirtua"]) ,dtFromDate ,dtToDate ,CreatedBy ); } i have used IIF function; it checks if datevalue is true for dbnull then adds null in database else the datevalue of datatable column

      Regards, Kapil Thakur (Where's there is Kapil , there is a way) - thakur.kapil@gmail.com

      K 1 Reply Last reply
      0
      • K Kapil Thakur

        try using the following code : foreach (DataRow dtRow in dtTrackingData.Rows) { SqlHelper.ExecuteNonQuery ( myConnectionString , "SP_NAME" , iWeekNo , Convert.ToInt32(dtRow["InvCoID"]) , IIF(IsDBNull(dtRow["LatestReportDateConsensus"]), "null" , dtRow["LatestReportDateConsensus"] ) , Convert.ToDateTime(dtRow["LatestReportDateVirtua"]) ,dtFromDate ,dtToDate ,CreatedBy ); } i have used IIF function; it checks if datevalue is true for dbnull then adds null in database else the datevalue of datatable column

        Regards, Kapil Thakur (Where's there is Kapil , there is a way) - thakur.kapil@gmail.com

        K Offline
        K Offline
        kishorgh
        wrote on last edited by
        #3

        didnt get that IIF whts tht??

        K 1 Reply Last reply
        0
        • K kishorgh

          didnt get that IIF whts tht??

          K Offline
          K Offline
          Kapil Thakur
          wrote on last edited by
          #4

          IIF is in vb.net for C# its ((what) ? then : else) Apologies for the goof up

          Regards, Kapil Thakur (Where's there is Kapil , there is a way) - thakur.kapil@gmail.com

          K 1 Reply Last reply
          0
          • K Kapil Thakur

            IIF is in vb.net for C# its ((what) ? then : else) Apologies for the goof up

            Regards, Kapil Thakur (Where's there is Kapil , there is a way) - thakur.kapil@gmail.com

            K Offline
            K Offline
            kishorgh
            wrote on last edited by
            #5

            my code is in C#..:( :(

            K 1 Reply Last reply
            0
            • K kishorgh

              my code is in C#..:( :(

              K Offline
              K Offline
              Kapil Thakur
              wrote on last edited by
              #6

              google for ((what) ? then : else) C#

              Regards, Kapil Thakur (Where's there is Kapil , there is a way) - thakur.kapil@gmail.com

              K 2 Replies Last reply
              0
              • K Kapil Thakur

                google for ((what) ? then : else) C#

                Regards, Kapil Thakur (Where's there is Kapil , there is a way) - thakur.kapil@gmail.com

                K Offline
                K Offline
                kishorgh
                wrote on last edited by
                #7

                search lottttttt but no success.. :(

                1 Reply Last reply
                0
                • K Kapil Thakur

                  google for ((what) ? then : else) C#

                  Regards, Kapil Thakur (Where's there is Kapil , there is a way) - thakur.kapil@gmail.com

                  K Offline
                  K Offline
                  kishorgh
                  wrote on last edited by
                  #8

                  got the solution...............:) SqlHelper.ExecuteNonQuery ( myConnectionString , "usp_InsertTrackingData" , iWeekNo , Convert.ToInt32(dtRow["InvCoID"]) , ((dtRow["LatestReportDateConsensus"] != DBNull.Value) ? dtRow["LatestReportDateConsensus"] : null) , ((dtRow["LatestReportDateVirtua"] != DBNull.Value) ? dtRow["LatestReportDateVirtua"] : null) ,dtFromDate ,dtToDate ,CreatedBy );

                  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