Obtenga datos de un objeto y póngalos en un cuadro de texto

I have an object which contains 2 pieces of information in objData[0]. The information is System_ID y Network_ID. The data is coming from a query to a database.

I want to get the data out of the object and display it in two separate text boxes, one for system_ID y uno para Network_ID. Right now I am putting them into a combo box.

Vea a continuación mi código:

    //get network ID and systenm name
    private void cmbAddItem_SelectedIndexChanged(object sender, EventArgs e)
        FASystems fSys = new FASystems(sConn);
        object objData =  fSys.getSystemNetworkIDFriendlyName(cmbAddItem.Text.ToString());
        cmbNetworkID.DataSource = objData;
        cmbNetworkID.DisplayMember = "Network_ID";
        cmbSysName.DataSource = objData;
        cmbSysName.DisplayMember = "System_Name";
        // txtNetworkID.Text = objData[0].Network_ID;

preguntado el 25 de agosto de 12 a las 10:08

What's exactly your problem? This is a fairly basic stuff... Furthermore, why you use a type object to store values like this? Create a class for this purpose. -

You are using an API of FA Systems. Don't they provide interfaces for working with their API? -

2 Respuestas

Assuming your C# compiler is 3.0 or up use the var keyword on the api call

var objData =  fSys.getSystemNetworkIDFriendlyName(cmbAddItem.Text.ToString()); 

Let's assume you're correct that there is an array now in objData with a type in it that has at least Network_ID as a member...

txtNetworkID.Text = objData[0].Network_ID;  

debería funcionar entonces.

Respondido 25 ago 12, 10:08

Can you post the function declaration for getSystemNetworkIDFriendlyName and show how you are populating the return type?

I recommend creating a new class to store the NetworkID and SystemID

class SystemInfo
   public string NetworkID { get; set; } 
   public string SystemId { get; set; } 

Rewrite the function getSystemNetworkIDFriendlyName to return an instance of SystemInfo. Then populating your textbox becomes:

 FASystems fSys = new FASystems(sConn);
 SystemInfo inf o=  fSys.getSystemNetworkIDFriendlyName(cmbAddItem.Text.ToString());
 txtNetworkID.Text = info.NetworkID;

Espero que esto ayude,


Respondido el 13 de Septiembre de 12 a las 12:09

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.