初学者,代码难看,莫怪.
我标记的代码运行不到,没有输出,好奇怪呀.有没有人帮解释一下.谢谢!!
    public class TestCode
    {
        private static List<string> ids = new List<string>();
        private static List<string> names = new List<string>();        private static string myConnstr;
        private static OleDbConnection myconn; // 数据库连接
        private static string mysql; // 数据库操作语句
        private static OleDbCommand mycommand = new OleDbCommand();
        private static string dbpath; // 数据库名        private static int InsertStartId;        // 初始化数据库.
        private static void initdatabase()
        {
            dbpath = "oledb.mdb";
            myConnstr = 
                @"Provider=Microsoft.Jet.OleDB.4.0;Data Source=" + 
                dbpath;
        }        // 查询数据库
        private static void findall()
        {
            ids.Clear();
            names.Clear();
            mysql = @"select id,user_name from users"; // 操作
            using (myconn)
            {
                myconn = new OleDbConnection(myConnstr);
                myconn.Open();
                mycommand.CommandText = mysql;
                mycommand.Connection = myconn;
                OleDbDataReader myreader = mycommand.ExecuteReader(); 
                int i = 0;
                while (myreader.Read())// 读取
                {
                    ids.Add(myreader["id"].ToString());
                    names.Add(myreader["user_name"].ToString());
                    i++;
                }                /***********这里好像没有运行*********************/                InsertStartId = i + 1;
                Console.WriteLine("Strat ID is: " + InsertStartId.ToString());                /***********这里好像没有运行*********************/                myconn.Close();
                myreader.Close();
            }
        }        // 插入数据库数据.
        private static bool insert()
        {
            mysql = 
                @"insert into users Values(
                '" + InsertStartId.ToString() +  @"',
                'insert" + InsertStartId.ToString() + @"')";
            using (myconn)
            {
                myconn = new OleDbConnection(myConnstr);
                myconn.Open();
                mycommand.CommandText = mysql;
                mycommand.Connection = myconn;
                if(mycommand.ExecuteNonQuery() > 0)
                {
                    return true;
                }
                else
                    return false;
            }
        }        public static void Main()
        {
            // ToDo: type todo code here;
            initdatabase();            while(true)
            {
                findall();
                foreach (string _name in names)
                {
                    Console.WriteLine(_name);
                }
                Console.WriteLine("Press Any Key To Insert!");
                Console.ReadKey();                if(insert())
                {
                    Console.WriteLine("Insert" + InsertStartId + "'th Data Success!!");
                    Console.WriteLine("Press Any Key To List Result!");
                    Console.ReadKey();
                }
            }
        }数据库C#