1
  1. I want to change last number of my every "No" for all students (who is born between 1996 and 1998) to 0, for example. (from 160456 to 1604560)
  2. I want to delete data for students whos "No" first 2 numbers is 14, for example. (user2.No = 143457;) How to find data only by 1 or more numbers?

I'm using Linq:

using System.Linq;
using Db4objects.Db4o.Linq;

My database look like this:

 User user1 = new User();
    user1.Name = "Bob";
    user1.Surname = "Topson";
    user1.No = 160456;
    user1.Birth = new DateTime (1998, 5, 12);

 User user2 = new User();
    user2.Name = "Rob";
    user2.Surname = "Simpson";
    user2.No = 143457;
    user2.Birth = new DateTime (1996, 8, 4);

my user.cs code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace db4o
{
    class User
    {
        public string Name { get; set; }
        public string Surname { get; set; }
        public int No { get; set; }
        public DateTime Birth { get; set; }
    }
}
PogChamp
  • 39
  • 4

1 Answers1

1

// Answer for first Question

 var r = from User p in db
                   // ling for some data from your db
                    where user1.Birth >= Convert.ToDateTime(1996 / 8 / 4) && user1.Birth <= Convert.ToDateTime(1998 / 8 / 4) 
                    select p;

            foreach (User p in r)
            {

                // Here I use some method
                // I'm not a C# programmer    
                int myint = p.No;
                string str1 = Convert.ToString(myint);
                str1 = str1.Remove(str1.Length - 1);
                str1 = str1 + "0";
                p.No =Convert.ToInt32(str1);

                // now save data
                db.Store(p);

               // print data
               Console.Write(string.Format("{0} {1}\n", p.Name, p.No));



            }