compare problem
-
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
-
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
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
-
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
-
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
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 aNULL
check. Do something likeif (dr["prod2"] != null)
{
string prod2 = dr["prod2"].ToString();
Label28.Visible = !(prod2 == "0");
Label28.Text = prod2;
}:)
Navaneeth How to use google | Ask smart questions