How to add ValueLabels to dynamically generated Labels

Aug 17, 2011 at 2:33 PM

Can someone please help me.

I have used the below code to Dynamically create Labels and ValueLabels based on the database records [ie,I get labels and ValueLabels from database]. This code works fine without any error and creates the Labels but I unable to see the ValueLabels when i view the .SAV file from SPSS tool. [ie, under the Variable View tab of SPSS tool, the ValueLabel columns disabled]

Please help me to fix this issue urgently.Thanks.

private void CreateMetaData(SpssDataDocument doc, DataSet dsRespondentData)
        {
            try
            {
                for (int i = 0; i < dsRespondentData.Tables[0].Columns.Count; i++)
                {
                    // Define dictionary
                    SpssStringVariable myColumn = new SpssStringVariable();
                    string columnname = dsRespondentData.Tables[0].Columns[i].ColumnName.ToString();
                    string labelname = GetLabelname(columnname, dsRespondentData.Tables[1]); // returns Label name
                    Hashtable ht = GetLabelValues(columnname, dsRespondentData.Tables[2]);      // returns ValueLabels if available
              
                    myColumn.Name = columnname.Trim();
                    myColumn.Label = labelname.Trim();
                    foreach (DictionaryEntry item in ht)
                    {
                        myColumn.ValueLabels.Add(item.Key.ToString(), item.Value.ToString());
                    }
                    myColumn.Length = ColumnSize;
                    doc.Variables.Add(myColumn);               

                }
                // Add some data
                doc.CommitDictionary();
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
}