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. compare problem

compare problem

Scheduled Pinned Locked Moved ASP.NET
helpcsharpasp-netdatabase
4 Posts 4 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.
  • P Offline
    P Offline
    prateekfgiet
    wrote on last edited by
    #1

    i m using asp.net with c# i submit some value in database and then access it i m trying to do when any fiels contain 0 value then labels visibility should be false. i m doing like this cmd.CommandText = "select * from invoice where invoice_no=(Select max(invoice_no) from invoice)"; adp.Fill(ds, "re"); foreach (DataRow dr in ds.Tables["re"].Rows) { Label49.Text = dr["invoice_no"].ToString(); Label2.Text = dr["indate"].ToString(); Label9.Text = dr["po_no"].ToString(); Label10.Text = dr["dc_no"].ToString(); Label11.Text = dr["comp_name"].ToString(); Label13.Text = dr["tin_no"].ToString(); Label68.Text = dr["total_vat"].ToString(); Label27.Text = dr["prod1"].ToString(); if (dr["prod2"].ToString() == 0) { Label28.Visible = false; } else { Label28.Text = dr["prod2"].ToString(); } but it will give error how i'll do if prod2 contain null or 0 value then label28.visible=false; plsease help me thanks in advance

    C L N 3 Replies Last reply
    0
    • P prateekfgiet

      i m using asp.net with c# i submit some value in database and then access it i m trying to do when any fiels contain 0 value then labels visibility should be false. i m doing like this cmd.CommandText = "select * from invoice where invoice_no=(Select max(invoice_no) from invoice)"; adp.Fill(ds, "re"); foreach (DataRow dr in ds.Tables["re"].Rows) { Label49.Text = dr["invoice_no"].ToString(); Label2.Text = dr["indate"].ToString(); Label9.Text = dr["po_no"].ToString(); Label10.Text = dr["dc_no"].ToString(); Label11.Text = dr["comp_name"].ToString(); Label13.Text = dr["tin_no"].ToString(); Label68.Text = dr["total_vat"].ToString(); Label27.Text = dr["prod1"].ToString(); if (dr["prod2"].ToString() == 0) { Label28.Visible = false; } else { Label28.Text = dr["prod2"].ToString(); } but it will give error how i'll do if prod2 contain null or 0 value then label28.visible=false; plsease help me thanks in advance

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

      prateekfgiet wrote:

      Label49.Text

      prateekfgiet wrote:

      Label68

      For the poor bugger (including you in a couple of months time) that will have to maintain this code, please name these things properly. Label49 or Label68 are not an acceptable names.

      prateekfgiet wrote:

      if (dr["prod2"].ToString() == 0)

      You are converting the value to a string, then comparing it with an integer. Why not keep both sides as integers or convert both sides to strings?

      Man who stand on hill with mouth open wait long time for roast duck to drop in

      1 Reply Last reply
      0
      • P prateekfgiet

        i m using asp.net with c# i submit some value in database and then access it i m trying to do when any fiels contain 0 value then labels visibility should be false. i m doing like this cmd.CommandText = "select * from invoice where invoice_no=(Select max(invoice_no) from invoice)"; adp.Fill(ds, "re"); foreach (DataRow dr in ds.Tables["re"].Rows) { Label49.Text = dr["invoice_no"].ToString(); Label2.Text = dr["indate"].ToString(); Label9.Text = dr["po_no"].ToString(); Label10.Text = dr["dc_no"].ToString(); Label11.Text = dr["comp_name"].ToString(); Label13.Text = dr["tin_no"].ToString(); Label68.Text = dr["total_vat"].ToString(); Label27.Text = dr["prod1"].ToString(); if (dr["prod2"].ToString() == 0) { Label28.Visible = false; } else { Label28.Text = dr["prod2"].ToString(); } but it will give error how i'll do if prod2 contain null or 0 value then label28.visible=false; plsease help me thanks in advance

        L Offline
        L Offline
        Leonscape
        wrote on last edited by
        #3

        Something like this

        if( DBNull.Value.Equals( dr["prod2"] ) || dr["prod2"].ToString() == "0")
        Label28.Visible = false;
        else
        Label28.Text = dr["prod2"].ToString();

        Using the wrong tool for the job is half the fun.

        1 Reply Last reply
        0
        • P prateekfgiet

          i m using asp.net with c# i submit some value in database and then access it i m trying to do when any fiels contain 0 value then labels visibility should be false. i m doing like this cmd.CommandText = "select * from invoice where invoice_no=(Select max(invoice_no) from invoice)"; adp.Fill(ds, "re"); foreach (DataRow dr in ds.Tables["re"].Rows) { Label49.Text = dr["invoice_no"].ToString(); Label2.Text = dr["indate"].ToString(); Label9.Text = dr["po_no"].ToString(); Label10.Text = dr["dc_no"].ToString(); Label11.Text = dr["comp_name"].ToString(); Label13.Text = dr["tin_no"].ToString(); Label68.Text = dr["total_vat"].ToString(); Label27.Text = dr["prod1"].ToString(); if (dr["prod2"].ToString() == 0) { Label28.Visible = false; } else { Label28.Text = dr["prod2"].ToString(); } but it will give error how i'll do if prod2 contain null or 0 value then label28.visible=false; plsease help me thanks in advance

          N Offline
          N Offline
          N a v a n e e t h
          wrote on last edited by
          #4

          prateekfgiet wrote:

          but it will give error how i'll do if prod2 contain null or 0 value then label28.visible=false;

          Don't call the ToString() before doing a NULL check. Do something like

          if (dr["prod2"] != null)
          {
          string prod2 = dr["prod2"].ToString();
          Label28.Visible = !(prod2 == "0");
          Label28.Text = prod2;
          }

          :)

          Navaneeth How to use google | Ask smart questions

          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