Click here to Skip to main content
14,970,456 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more: , +
I am passing data from Dataset to a Variable of data type int.
I even tried to make a new combo box by writing this:
ComboBox cb1 =  new ComboBox();
cb1.DataSource = ds.Tables[0].DefaultView;
cb1.ValueMember = "xyz";

After that I tried to pass value to the variable, but runtime error occurs.

Any Solution?

Thanks in Advance !!!

By using where condition to get the selected data, I have created Dataset programatically. Then programatically Created Combobox as above mentioned, and then pass the value in an Integer Variable, which is not been done.
Any solution on how to pass value from dataset to an Integer Variable.
Updated 13-Mar-12 7:48am
André Kraak 11-Mar-12 14:54pm
Edited question:
Added pre tags
Formatted text/code
Sergey Alexandrovich Kryukov 11-Mar-12 15:06pm
Solution for what? You did not even show your exception (exception, not "run-time error).
Varun Sareen 12-Mar-12 0:32am
show us the error

1 solution

You can convert the DataSet table into the List of dynamic variable by using this method

private static List<dynamic> ConvertToDynamiList(DataTable dtObject)
            var columns = dtObject.Columns.Cast<datacolumn>();

            var dictionaryList = dtObject.AsEnumerable()
                .Select(dataRow => columns
                    .Select(column =>
                        new { Column = column.ColumnName, Value = dataRow[column] })
                             .ToDictionary(data => data.Column, data => data.Value)).ToList().ToArray();

            var result = new List<dynamic>();

            foreach (var emprow in (List<system.collections.idictionary>)dictionaryList.ToList<idictionary>())
                var row = (IDictionary<string,>)new System.Dynamic.ExpandoObject();
                Dictionary<string,> eachEmpRow = (Dictionary<string,>)emprow;

                foreach (KeyValuePair<string,> keyValuePair in eachEmpRow)

            return result;

and after getting the dynamic variable list you can use it for binding combobox or you can access the integer variabls from the list

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900