日期:2014-05-17  浏览次数:20775 次

奇怪,数据库操作,为什么有些代码没有运行?
初学者,代码难看,莫怪.
我标记的代码运行不到,没有输出,好奇怪呀.有没有人帮解释一下.谢谢!!
    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())// 读取
                {
                   &n