将数据从数据集传递到变量类型int

将数据从数据集传递到变量类型int

本文介绍了将数据从数据集传递到变量类型int的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将数据从数据集传递到数据类型为int的变量.
我什至尝试通过编写以下代码来制作一个新的组合框:

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";


之后,我尝试将值传递给变量,但发生运行时错误.

有解决方案吗?

在此先感谢!!!

通过使用where条件获取所选数据,我以编程方式创建了Dataset.然后按上述方式以编程方式创建Combobox,然后将值传递到Integer变量中,此操作尚未完成.

有关如何将值从数据集传递到整数变量的任何解决方案.


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.
OR
Any solution on how to pass value from dataset to an Integer Variable.

推荐答案

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)
                {
                    row.Add(keyValuePair);
                }
                result.Add(row);
            }

            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


这篇关于将数据从数据集传递到变量类型int的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 03:26