コード例 #1
0
        static void Main(string[] args)
        {
            MySqlite db = new MySqlite("mydb.db3");

            db.connect();

            try
            {
                db.executeQuery("create table users(" +
                                "id integer primary key autoincrement," +
                                "username varchar(32)," +
                                "password varchar(128))");
            } catch (SQLiteException e) {
                Console.WriteLine("{0}", e.Message);
            }

            string[,] users = new string[50, 2];
            for (int n = 0; n < 50; n++)
            {
                users[n, 0] = "user_" + n.ToString();
                users[n, 1] = "pass_" + n.ToString();
            }

            db.fastInserts("users", "NULL, ?,?", users);

            DataSet dataSet = db.select("select * from users;");

            foreach (DataTable t in dataSet.Tables)
            {
                Console.WriteLine("Tabela {0} zawiera {1} wiersze", t.TableName, t.Rows.Count);
                foreach (DataRow r in t.Rows)
                {
                    Console.Write("-> ");
                    foreach (DataColumn c in t.Columns)
                    {
                        Console.Write("{0}={1}, ", c.ColumnName, r[c.ColumnName]);
                    }
                    Console.WriteLine();
                }
            }

            dataSet.Dispose();

            SQLiteDataAdapter da = db.getAdapter("select * from users;", true);
            DataSet           ds = db.getData(da);

            DataRow[] drows = ds.Tables[0].Select("username = '******'");
            for (int i = 0; i < drows.Length; i++)
            {
                drows[i].BeginEdit();
                drows[i]["password"] = "******";
                drows[i].EndEdit();
            }
            Console.WriteLine("zmodyfikowano: {0} wierszy", da.Update(ds));
            ds.Dispose();
            da.Dispose();

            dataSet = db.select("select * from users;");
            foreach (DataTable t in dataSet.Tables)
            {
                Console.WriteLine("Tabela {0} zawiera {1} wiersze", t.TableName, t.Rows.Count);
                foreach (DataRow r in t.Rows)
                {
                    Console.Write("-> ");
                    foreach (DataColumn c in t.Columns)
                    {
                        Console.Write("{0}={1}, ", c.ColumnName, r[c.ColumnName]);
                    }
                    Console.WriteLine();
                }
            }

            db.close();
            Console.ReadLine();
        }
コード例 #2
0
        static void Main(string[] args)
        {
            MySqlite db = new MySqlite("mydb.db3");
            db.connect();

            try
            {
                db.executeQuery("create table users(" +
                                "id integer primary key autoincrement," +
                                "username varchar(32)," +
                                "password varchar(128))");
            } catch (SQLiteException e) {
                Console.WriteLine("{0}", e.Message);
            }

            string[,] users = new string[50, 2];
            for (int n = 0; n < 50; n++) {
                users[n, 0] = "user_" + n.ToString();
                users[n, 1] = "pass_" + n.ToString();
            }

            db.fastInserts("users", "NULL, ?,?", users);

            DataSet dataSet = db.select("select * from users;");
            foreach (DataTable t in dataSet.Tables)
            {
                Console.WriteLine("Tabela {0} zawiera {1} wiersze", t.TableName, t.Rows.Count);
                foreach (DataRow r in t.Rows)
                {
                    Console.Write("-> ");
                    foreach (DataColumn c in t.Columns)
                        Console.Write("{0}={1}, ", c.ColumnName, r[c.ColumnName]);
                    Console.WriteLine();
                }
            }

            dataSet.Dispose();

            SQLiteDataAdapter da = db.getAdapter("select * from users;", true);
            DataSet ds = db.getData(da);

            DataRow[] drows = ds.Tables[0].Select("username = '******'");
            for (int i = 0; i < drows.Length; i++)
            {
                drows[i].BeginEdit();
                drows[i]["password"] = "******";
                drows[i].EndEdit();
            }
            Console.WriteLine("zmodyfikowano: {0} wierszy", da.Update(ds));
            ds.Dispose();
            da.Dispose();

            dataSet = db.select("select * from users;");
            foreach (DataTable t in dataSet.Tables)
            {
                Console.WriteLine("Tabela {0} zawiera {1} wiersze", t.TableName, t.Rows.Count);
                foreach (DataRow r in t.Rows)
                {
                    Console.Write("-> ");
                    foreach (DataColumn c in t.Columns)
                        Console.Write("{0}={1}, ", c.ColumnName, r[c.ColumnName]);
                    Console.WriteLine();
                }
            }

            db.close();
            Console.ReadLine();
        }