store each row in new table permanetly using foreach()

ShumzShumz INMember ✭✭
edited February 2017 in Xamarin.Android

hey friends , need to find out the changes that i have to do in code below in order to add each row in a table using foreach()...

this below code is working fine:

var items = await eCampusDatabase.DataInstance.GetAllItemsWithQuery(new string[] { "class_id" }, new string[] { Settings.ClassID });
if (items.Count != null || items.Count > 0)
{

                    foreach (var abc in items)
                    {
                        var tables = new List<AllSelectedItems>
                {

                    new AllSelectedItems() { student_id = abc.student_id, class_id = abc.class_id, student_name = abc.student_name, IsPresent = abc.IsPresent, Uploaded = abc.Uploaded, AttendanceDate = abc.AttendanceDate, Userid = abc.Userid, CurrentDateTime = abc.CurrentDateTime, AttendanceIn = abc.AttendanceIn }
                };

                    }
                    Toast.MakeText(this.Activity, AllItem.Count.ToString(), ToastLength.Long).Show();
                    Toast.MakeText(this.Activity, items.Count.ToString(), ToastLength.Long).Show();

                }

but this code is storing one last row that is one row ...but i want to store each row of "items" and for that i tried the following changes in above code and they are as follow

var items = await eCampusDatabase.DataInstance.GetAllItemsWithQuery(new string[] { "class_id" }, new string[] { Settings.ClassID });
if (items.Count != null || items.Count > 0)
{

                    foreach (var abc in items)
                    {
                        var tables = new List<AllSelectedItems>
                {
                            foreach (var abc in items)
                        {

                            new AllSelectedItems() { student_id = abc.student_id, class_id = abc.class_id, student_name = abc.student_name, IsPresent = abc.IsPresent, Uploaded = abc.Uploaded, AttendanceDate = abc.AttendanceDate, Userid = abc.Userid, CurrentDateTime = abc.CurrentDateTime, AttendanceIn = abc.AttendanceIn }


                             }
                    };


                    Toast.MakeText(this.Activity, AllItem.Count.ToString(), ToastLength.Long).Show();
                    Toast.MakeText(this.Activity, items.Count.ToString(), ToastLength.Long).Show();

                }

but this give me so many error...but i think using foreach aftr creating a table will be a solution...plz tell me the changes in code i have to make in order to store all rows of "items" in "tables"

Sign In or Register to comment.