//插入user資料表,一筆email和名字的紀錄。 _dbCmd.CommandText = "INSERT INTO user(email,name) VALUES ('email','name')"; _dbCmd.ExecuteNonQuery(); dbCmd.CommandText = "INSERT INTO user(email,name) VALUES ('dd@com','許秝維')"; _dbCmd.ExecuteNonQuery(); //更新user資料表,將名為bbn的名字都改為Codelicious _dbCmd.CommandText = "UPDATE user SET name = 'Codelicious' WHERE name = 'bbn'"; _dbCmd.ExecuteNonQuery(); //刪除user資料表 cmd.CommandText = "Drop Table user"; cmd.ExecuteNonQuery(); //在user資料表中,搜尋名為'許秝維',且email為dd@com的紀錄 _dbCmd.CommandText = "SELECT ID, name,email FROM user where name='許秝維' and email='dd@com'"; SQLiteDataReader reader = _dbCmd.ExecuteReader(); if (reader.HasRows) { while (reader.Read()) { Console.WriteLine("ID: " + reader.GetInt32(0)); Console.WriteLine("name: " + reader.GetString(1)); Console.WriteLine("email: " + reader.GetString(2)); } } reader.Close(); //取得最後一筆紀錄 _dbCmd.CommandText = "SELECT * FROM " + TABLE_FILE + " ORDER BY id DESC"; SQLiteDataReader reader = _dbCmd.ExecuteReader(); if (reader.HasRows) { while (reader.Read()) { Console.WriteLine("ID: " + reader.GetInt32(0)); Console.WriteLine("name: " + reader.GetString(1)); Console.WriteLine("email: " + reader.GetString(2)); break; } } reader.Close(); //建立資料表 //Check table file exist? _dbCmd.CommandText = "SELECT name FROM sqlite_master WHERE type='table' AND name='" + TABLE_FILE + "'"; dataReader = _dbCmd.ExecuteReader(); if (!dataReader.HasRows) { dataReader.Close(); _dbCmd.CommandText = "Create Table " + TABLE_FILE + " (id INTEGER PRIMARY KEY ASC, name ,path,tags,comment)"; _dbCmd.ExecuteNonQuery(); } else { dataReader.Close(); } //判斷屬性的資料型態 if (reader.HasRows) { while (reader.Read()) { for(int i=0;i<reader.FieldCount;i++) { if (reader.GetName(i).CompareTo("id") == 0) { if (reader.GetFieldType(i) == typeof(string)) { dataResult[i]= reader.GetString(i); } else if (reader.GetFieldType(i) == typeof(Int64)) { dataResult[i] = reader.GetInt64(i).ToString(); } else if (reader.GetFieldType(i) == typeof(Int32)) { dataResult[i] = reader.GetInt32(i).ToString(); } else if (reader.GetFieldType(i) == typeof(Int16)) { dataResult[i] = reader.GetInt16(i).ToString(); } else if (reader.GetFieldType(i) == typeof(Boolean)) { dataResult[i] = reader.GetBoolean(i).ToString(); } else if (reader.GetFieldType(i) == typeof(Int64)) { dataResult[i] = reader.getobj.GetInt64(i).ToString(); } } } //Console.WriteLine("ID: " + reader.get.GetInt32(0)); //Console.WriteLine("name: " + reader.GetString(1)); //Console.WriteLine("email: " + reader.GetString(2)); } } reader.Close();
2013年8月21日 星期三
使用sqlite
嗨,大家好!我是一位資訊人、畫畫人、科技人和行銷人。定位自己為網路觀察家,永遠保持好奇心與熱情,學習跨領域新事物,希望最終能成為一個全方位的人。喜歡探索新技術和創意,並將其應用於工作和生活中。也喜歡畫畫、旅行、閱讀和寫作。希望我的部落格可以為您帶來啟發和樂趣,並與您分享我的經驗和見解。謝謝您的訪問,期待與您交流!
訂閱:
張貼留言 (Atom)
沒有留言:
張貼留言