I have this webservice that connects to my database via a table adapter and I am trying to read the column value based on the controls passed by an AJAX script that I wrote. I tried to use a hash table to replicate the actual database column.

What I like to accomplish is to use to concatinate the hash value into the row property of the table and I can't get to work. Now I don't know if my implementation is feasible, but if anyone knows a way to accomplish what I am trying to do, I would appreciate it.

[WebMethod]
    public int GetAlertSetting(string Control, int ContactID)
    {
        Hashtable ContactHash = new Hashtable();
        int AlertsValue = 0;
        ContactHash.Add("rdoLB", "LowBattery");
        ContactHash.Add("rdoGeo", "Geofence");
        ContactHash.Add("rdoAC", "AcDc");
        ContactHash.Add("rdoCU", "Capacity");

        string HashValue = Convert.ToString(ContactHash[Control]);

        AlertsTableAdapter GAlerts = new AlertsTableAdapter();
        GeoPlane.AlertsDataTable GAlertsTable = GAlerts.GetAlertsByContactID(ContactID);
        GeoPlane.AlertsRow GAlertsRow = GAlertsTable[0];

        AlertsValue = GAlertsRow.ContactHash[Control];  //don't know if this is correct.
        return (AlertsValue);
  
        //I could also return the value like this
       return(GAlertsRow.ContactHash[Control]);  //If I can get the above to work.
    }

Do you have to use a hash table?

I am fine with the title of your problem, but your description just confused me.

Can't you use a Select Case statement to retrieve the value of the radio list (if it is a radio list), then do your information depending on the value it retrieves?

This data table has growth potential and adding a value to the hash table is much more easy to accomplish then to write a complete case statement (at least that's what I was thinking). You know us UNIX developer's can be very lazy sometimes. I did however consider the case statement, but is there a work around?

if you're certain that there can only be one radio checked at all times, then you need to relate your radio value to the lookup of the database.

However, I would strong recommend just doing something like this:

switch (radiogroupname) {
  case "val1" :  str = valuetopass;
  case "val2" :  str = valuetopass;
  case "val3" :  str = valuetopass;
  default :  str = valuetopass;
}

sql = "INSERT......."
parameter..

I was able to solve the problem the way my colleague wanted it to run. there is a small performance penalty because of the hash table but it's not very noticeable. Here is the solution.

public int GetAlertSetting(string Control, int ContactID)
    {
        Hashtable AlertsHash = new Hashtable();
        int AlertsValue = 0;

        ATableAdapter GAlerts = new ATableAdapter();
        Jean.ADataTable GAlertsTable = GAlerts.GetAByContactUID(ContactID);
        Jean.ARow GARow = GATable[0];

        if (GAlertsTable.Count > 0)
        {
            AlertsHash.Add("rdoLB", GARow.column);
            AlertsHash.Add("rdoAC", GARow.column);
            AlertsHash.Add("rdoCU", GARow.column);
            AlertsHash.Add("rdoIR", GARow.column);
            AlertsHash.Add("rdoRF", GARow.column);
            AlertsHash.Add("rdoPS", GARow.column);
            AlertsHash.Add("rdoVib", GARow.column);
            AlertsHash.Add("rdoTR", GARow.column);
            AlertsValue = Convert.ToInt16(AlertsHash[Control]);
        }
        else
        {
            AlertsValue = 999;
        }
        return (AlertsValue);
    }

That passes the value to the database? You lost me somewhere lol.

what I found out is that the query that he is using returns an entire row/record and not a single value. Also since the query is in use by other program parts, he wanted to use the same query to only retrieve the column information based on the value of a radio button for example

<input type="radio" id=rdoControl" name="ControlPanel" etc...... />

what is ultimately needed to be accomplish is a way to map the radio control to a specific column on the data table.

oh woops. I thought you wanted to insert a value into the database depending on the chosen radio button.

No wonder why I was confused, and unhelpful.

It's OK. Maybe I wasn't as descriptive as should have been.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.