Click here to Skip to main content
15,905,867 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
If I have 3 IP address the out of which two are live and one is at Off state. but the
dr["Status"] = "Y"; and dr["Status"] = "N"; only shows N in all records. Please help

C#
protected void Page_Load(object sender, EventArgs e)
        {
            SqlDataAdapter da = new SqlDataAdapter("SELECT PS, PS_IP_ADDRESS FROM m_police_station where STATE_CD=21 and PS_IP_ADDRESS is not Null and LANG_CD=99", con);
            DataSet ds = new DataSet();
            da.Fill(ds);

            List<string> strIP = new List<string>();    
            foreach(DataRow row in ds.Tables[0].Rows)
            {
                strIP.Add(row["PS_IP_ADDRESS"].ToString());
            }
         
            DataTable dt = ds.Tables[0];
            dt.Columns.Add("Status", typeof(string));
             
            foreach (DataRow dr in dt.Rows)
            {               
                foreach (string s in strIP)
                {
                    Ping p = new Ping();
                    PingReply r;
                                                //   String str = "10.0.0.0"; 
                    r = p.Send(s);
                    Response.Buffer = false;

                    if (r.Status == IPStatus.Success)
                    {
                        dr["Status"] = "Y";     //   Response.Write("Success \n");
                    }
                    else
                    {
                          dr["Status"] = "N";  //  Response.Write("fail");
                    }
                }

                Grid_Online_offline.DataSource = dt;
                Grid_Online_offline.DataBind();

            }

        }
Posted
Updated 18-Sep-13 21:22pm
v3

1 solution

C#
if (r.Status == IPStatus.Success)
                    {
                        dr["Status"] = "Y";     //   Response.Write("Success \n");
                    }
                    else
                    {
                          dr["Status"] = "N";  //  Response.Write("fail");
                    }



The status you update for the IP is Only "N". Please change this.
 
Share this answer
 
Comments
Shagun Bansal 19-Sep-13 3:21am    
for sucess it iy "Y" and for else its "N"

if (r.Status == IPStatus.Success)
{
dr["Status"] = "Y"; // Response.Write("Success \n");
}
else
{
dr["Status"] = "N"; // Response.Write("fail");
}

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900