I am trying to get my database data in particular variable.
my database handling class and i am trying to store data in currunt form class

var list = x.Rows();
if (list.Count != 0)
{
    Object[] ar = new Object[4];
    //Object[] ar = list[0];
    list.CopyTo(ar, 0);
    var quntity1 = (int) ar[0];
}

and row method

public List<Object> Rows()
        {
            List<Object> list = new List<Object>();
            Cn.Open();
            Dr = Cmd.ExecuteReader();
            while (Dr.Read())
            {
                Object[] array = new Object[Dr.FieldCount];
                Dr.GetValues(array);
                list.Add(array);
            }
            return list;
        }

in my table total 3 Columns and i m trying to get 2nd column

2.
i have one more question

i am trying to refresh datagridview data when i am press refresh button

datagridview.Refresh();

but its not working.

i got it my answer just replace row method's return type with object array and create list object[] inserted of list object.

var list = x.Rows();
if (list.Count != 0)
{
    Object[] ar = list[0];
    var quntity1 = (int) ar[1];
}

and row method

public List<Object[]> Rows()
    {
        List<Object[]> list = new List<Object[]>();
        Cn.Open();
        Dr = Cmd.ExecuteReader();
        while (Dr.Read())
        {
            Object[] array = new Object[Dr.FieldCount];
            Dr.GetValues(array);
            list.Add(array);
        }
        return list;
    }

its work for me

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.