I have a problem with this code plz some one fix it...

i have code so far but i don't understand why its not displaying r

Page 1 of 1

6 Replies - 564 Views - Last Post: 11 October 2009 - 08:22 PM Rate Topic: -----

#1 kernal  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 24
  • Joined: 09-August 09

I have a problem with this code plz some one fix it...

Posted 08 October 2009 - 04:11 AM

It run perfectly and show only the MAC address of my Wireless but it don't show any thing else. plz somebody help me...
	   private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
		{

			ManagementObjectSearcher search = new ManagementObjectSearcher("SELECT * FROM Win32_NetworkAdapter");
			if (e.Node.Text == "NVIDIA nForce 10/100 Mbps Ethernet")


			foreach (ManagementObject info in search.Get())
			{
				try
				{


					//textBox1.Text=info["NetworkAddresses[]"].ToString();
					//textBox1.Text = info["IPAddress[ ]"].ToString();
					if (info["MACAddress"].ToString() == "00:1E:68:12:36:AF")
					textBox2.Text = info["MACAddress"].ToString();
					textBox3.Text = info["MaxSpeed"].ToString();
					textBox4.Text = info["AdapterType"].ToString();
					textBox5.Text = info["NetConnectionStatus"].ToString();
					textBox6.Text = info["Manufacturer"].ToString();
					textBox7.Text = info["GUID"].ToString();
				}
				catch (Exception)
				{ }
			}

			if (e.Node.Text == "Atheros AR5007 802.11b/g WiFi Adapter")
			{

				foreach (ManagementObject info in search.Get())
				{
					try
					{
						// if (info["Name"].ToString() == "Atheros AR5007 802.11b/g WiFi Adapter" || info["Name"].ToString() == "NVIDIA nForce 10/100 Mbps Ethernet")

						//textBox1.Text=info["NetworkAddresses[]"].ToString();
						//textBox1.Text = info["IPAddress[ ]"].ToString();
						if (info["MACAddress"].ToString() == "00:1F:3A:33:7E:D4")
							textBox2.Text = info["MACAddress"].ToString();
							textBox3.Text = info["MaxSpeed"].ToString();
							textBox4.Text = info["AdapterType"].ToString();
							textBox5.Text = info["NetConnectionStatus"].ToString();
							textBox6.Text = info["Manufacturer"].ToString();
							textBox7.Text = info["GUID"].ToString();
					}
					catch (Exception)
					{ }
				}
			}


Mod Edit: When you are posting code please use code tags like this. :code:

Is This A Good Question/Topic? 0
  • +

Replies To: I have a problem with this code plz some one fix it...

#2 micalexlea  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 19-February 09

Re: I have a problem with this code plz some one fix it...

Posted 08 October 2009 - 04:56 AM

put a break point on your catch or a display the exception

i think an exception in been thrown
Was This Post Helpful? 0
  • +
  • -

#3 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6074
  • View blog
  • Posts: 23,539
  • Joined: 23-August 08

Re: I have a problem with this code plz some one fix it...

Posted 08 October 2009 - 05:43 AM

You do realize that this:
if (info["MACAddress"].ToString() == "00:1E:68:12:36:AF")
	textBox2.Text = info["MACAddress"].ToString();
	textBox3.Text = info["MaxSpeed"].ToString();
	textBox4.Text = info["AdapterType"].ToString();
	textBox5.Text = info["NetConnectionStatus"].ToString();
	textBox6.Text = info["Manufacturer"].ToString();
	textBox7.Text = info["GUID"].ToString();


is only going to set textBox2.Text if the MAC address matches, right? The other entries -- if they exist -- will still be printed regardless.
Was This Post Helpful? 0
  • +
  • -

#4 Aeternalis  Icon User is offline

  • D.I.C Regular

Reputation: 28
  • View blog
  • Posts: 291
  • Joined: 13-July 09

Re: I have a problem with this code plz some one fix it...

Posted 08 October 2009 - 05:43 AM

try putting this in :


 catch (Exception err)
		{
			lblResults.Text = "Error caught in treeView1_AfterSelect function: . ";
			lblResults.Text += err.Message;
}




You'll have to add a label somewhere in your aspx code called lblResults to view the error message, or alternatively you can set a breakpoint on one of those lines of code and see the error in the debugger. Either way.. it doesn't help much to catch the error if your going to do nothing with it.

Also.. your if statement is only applied to the first statement in your list of textbox assignments. If you put braces in around them the entire output will be disabled for objects that do not pass the If check..

Aet
Was This Post Helpful? 0
  • +
  • -

#5 StCroixSkipper  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 10
  • View blog
  • Posts: 121
  • Joined: 23-December 08

Re: I have a problem with this code plz some one fix it...

Posted 08 October 2009 - 08:27 AM

I would go one step further and code in the catch block to get the entire exception history. Code like:
catch(Exception err)
{
	while(err != null)
	{
		lblResults.Text += string.format("{0, }", err.Message);
		err = err.InnerException;
	}
}


Was This Post Helpful? 0
  • +
  • -

#6 kernal  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 24
  • Joined: 09-August 09

Re: I have a problem with this code plz some one fix it...

Posted 09 October 2009 - 10:50 AM

When i remove the ""if condition from the Nodes then it works"". plz help me
Was This Post Helpful? 0
  • +
  • -

#7 Ikonmx  Icon User is offline

  • New D.I.C Head

Reputation: 5
  • View blog
  • Posts: 45
  • Joined: 19-August 09

Re: I have a problem with this code plz some one fix it...

Posted 11 October 2009 - 08:22 PM

If you don't put braces after an if statement only the next statement will be conditionally executed

 
		 if (info["MACAddress"].ToString() == "00:1E:68:12:36:AF")
		 {
					textBox2.Text = info["MACAddress"].ToString();
					textBox3.Text = info["MaxSpeed"].ToString();
					textBox4.Text = info["AdapterType"].ToString();
					textBox5.Text = info["NetConnectionStatus"].ToString();
					textBox6.Text = info["Manufacturer"].ToString();
					textBox7.Text = info["GUID"].ToString()
		  }



With braces all the statements get executed.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1