//建立資料表 SQLiteConnection conn = new SQLiteConnection("Data source=mydb.sqlite"); //Open conn.Open(); //要下任何命令先取得該連結的執行命令物件 SQLiteCommand cmd = conn.CreateCommand(); // 建立資料表 string sql = "CREATE TABLE IF NOT EXISTS 'address_book' (sid INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL , name VARCHAR, phone VARCHAR, address VARCHAR,creation_date DATETIME DEFAULT CURRENT_TIMESTAMP)"; cmd.Connection = conn; cmd.CommandText = sql; cmd.ExecuteNonQuery(); // 輸入參數 cmd.Parameters.Add(cmd.CreateParameter()); cmd.Parameters.Add(cmd.CreateParameter()); cmd.Parameters.Add(cmd.CreateParameter()); cmd.CommandText = "INSERT INTO 'address_book' ('name', 'phone', 'address' ) VALUES( ?, ?, ?)"; cmd.Parameters[0].Value = TextBox1.Text; cmd.Parameters[1].Value = TextBox2.Text; cmd.Parameters[2].Value = TextBox3.Text; cmd.ExecuteNonQuery(); // 查詢資料表 cmd.CommandText = "SELECT * FROM address_book"; // 執行查詢塞入 sqlite_datareader SQLiteDataReader sqlite_datareader = cmd.ExecuteReader(); GridView1.DataSource = sqlite_datareader; GridView1.DataBind(); conn.Close();