Click here to Skip to main content
15,906,816 members
Home / Discussions / C#
   

C#

 
QuestionCalling Custom keys from a Web Config File Pin
iamnew2C#19-Oct-06 9:04
iamnew2C#19-Oct-06 9:04 
QuestionDownloading .NET Pin
bolddoggz19-Oct-06 8:57
bolddoggz19-Oct-06 8:57 
AnswerRe: Downloading .NET Pin
Christian Graus19-Oct-06 9:47
protectorChristian Graus19-Oct-06 9:47 
QuestionTree View Search Pin
joshp121719-Oct-06 8:44
joshp121719-Oct-06 8:44 
AnswerRe: Tree View Search Pin
mav.northwind20-Oct-06 22:10
mav.northwind20-Oct-06 22:10 
QuestionDPI-setting problem Pin
Bekjong19-Oct-06 5:15
Bekjong19-Oct-06 5:15 
QuestionFree Hand Drawing in PowerPoint through C# Pin
jonolo19-Oct-06 5:04
jonolo19-Oct-06 5:04 
QuestionDynamically retrieving WMI Data - A little help please! Pin
junus19-Oct-06 4:46
junus19-Oct-06 4:46 
Hi there, i get an exception while using C# and wmi to retrieve some data.
So here is the code is wrote:

<br />
   public class Adapter<br />
    {<br />
        public static ManagementObjectCollection GetNicAdapters()<br />
        {<br />
            try<br />
            {<br />
                WqlObjectQuery WQO = new WqlObjectQuery("SELECT * FROM Win32_NetworkAdapter WHERE NetConnectionStatus != null");<br />
                ManagementObjectSearcher MOS = new ManagementObjectSearcher(WQO);<br />
                ManagementObjectCollection MOC = MOS.Get();<br />
                return MOC;<br />
            }<br />
            catch (Exception ex)<br />
            {<br />
                MessageBox.Show("Data couldn't be retrieved.");<br />
                return null;<br />
            }<br />
        }<br />


I use this function to populate a field in my Form1 Base form. On the form (visually) there is a combo box, which now is filled with the Description of the Object.
All of this works so far but now i am getting problems:

<br />
        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)<br />
        {<br />
            <br />
            if (Adapters != null)<br />
            {<br />
                try<br />
                {<br />
                    ManagementObject[] MOArray = new ManagementObject[Adapters.Count];<br />
                    Adapters.CopyTo(MOArray, 0);<br />
<br />
                    int select = comboBox1.SelectedIndex;<br />
                    int selectedIndex   = int.Parse(MOArray[select]["Index"].ToString());<br />
                    int status          = int.Parse(MOArray[select]["NetConnectionStatus"].ToString());<br />
<br />
                    string myQueryString = "SELECT * FROM Win32_NetworkAdapterConfiguration WHERE Index = " + selectedIndex.ToString();<br />
<br />
                    WqlObjectQuery ConfigQuery = new WqlObjectQuery(myQueryString);<br />
                    ManagementObjectSearcher ConfigSearcher = new ManagementObjectSearcher(ConfigQuery);<br />
                    ManagementObjectCollection ManagementObjectConfigurations = ConfigSearcher.Get();<br />
<br />
                    ManagementObject[] CurrentArray = new ManagementObject[ManagementObjectConfigurations.Count];<br />
<br />
                    ManagementObjectConfigurations.CopyTo(CurrentArray, 0);<br />
                    ManagementObject CurrentConfig = CurrentArray[0];<br />
<br />
                    #region Draw Status<br />
                    IconConverter IC = new IconConverter();<br />
                    switch (status)<br />
                    {<br />
                        case 0:<br />
                            l_status.Text = "Gerät nicht angeschlossen";<br />
                            pb_status.Image = (Image)IC.ConvertTo(Switch.Properties.Resources.status_disconnected, typeof(Image));<br />
                            break;<br />
// other cases for the status<br />
                    }<br />
                    #endregion<br />
<br />
                    l_MAC.Text = CurrentConfig["MACAddress"].ToString();<br />
                    l_host.Text = CurrentConfig["DNSHostName"].ToString();<br />
                    l_svc.Text = CurrentConfig["ServiceName"].ToString();<br />
<br />
                }<br />
                catch (Exception ex)<br />
                {<br />
                    MessageBox.Show(ex.ToString());<br />
                }<br />
}<br />


Executing the code i get a NullReferenceException where it says:

l_MAC.Text = CurrentConfig["MACAddress"].ToString();

So why is the MACAddress Property not set? It seems to be that the second wql query isn't working, but why? please help me i am soooo close to loosing it and throwing my laptop out of my window!


please rescue me.thanx in advance.
QuestionMake property from base class protected Pin
topcatalpha19-Oct-06 4:43
topcatalpha19-Oct-06 4:43 
AnswerRe: Make property from base class protected Pin
Dustin Metzgar19-Oct-06 4:52
Dustin Metzgar19-Oct-06 4:52 
GeneralRe: Make property from base class protected Pin
topcatalpha19-Oct-06 5:15
topcatalpha19-Oct-06 5:15 
Questionusing the selectionformula property Pin
haseeb_saeed18-Oct-06 21:19
haseeb_saeed18-Oct-06 21:19 
Questionusing the selectionformula property for crystalreport viewer Pin
haseeb_saeed18-Oct-06 21:16
haseeb_saeed18-Oct-06 21:16 
Questionusing dbf in c# .net Pin
Amar Chaudhary18-Oct-06 19:53
Amar Chaudhary18-Oct-06 19:53 
AnswerRe: using dbf in c# .net Pin
baerten19-Oct-06 22:40
baerten19-Oct-06 22:40 
GeneralRe: using dbf in c# .net Pin
Amar Chaudhary19-Oct-06 23:48
Amar Chaudhary19-Oct-06 23:48 
GeneralRe: using dbf in c# .net Pin
mcgahanfl20-Oct-06 6:06
mcgahanfl20-Oct-06 6:06 
GeneralRe: using dbf in c# .net Pin
mcgahanfl20-Oct-06 6:07
mcgahanfl20-Oct-06 6:07 
QuestionDownload file from http address with authentication Pin
haritus18-Oct-06 19:52
haritus18-Oct-06 19:52 
AnswerRe: Download file from http address with authentication Pin
Le centriste19-Oct-06 4:29
Le centriste19-Oct-06 4:29 
QuestionRequired Field Validator Pin
bhanu1234518-Oct-06 19:31
bhanu1234518-Oct-06 19:31 
Questionvisual studio express - stand alone app ? [modified] Pin
bryce18-Oct-06 16:27
bryce18-Oct-06 16:27 
AnswerRe: visual studio express - stand alone app ? Pin
Dave Kreskowiak18-Oct-06 17:51
mveDave Kreskowiak18-Oct-06 17:51 
GeneralRe: visual studio express - stand alone app ? Pin
bryce18-Oct-06 18:25
bryce18-Oct-06 18:25 
AnswerRe: visual studio express - stand alone app ? Pin
Guffa18-Oct-06 18:34
Guffa18-Oct-06 18:34 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.