update.php

<form action="" method="post" name="form1"><br>
Input address book data:<br>
<input name="name" type="text" value="
<?php
    if($_POST['submit']=='Update') {
		echo $_POST['name'];
	}
	else {
		echo $_GET['name'];
	}
?>
"><br>
<input name="phone" type="text" value="
<?php
    if($_POST['submit']=='Update') {
		echo $_POST['phone'];
	}
	else {
		echo $_GET['phone'];
	}
?>
"><br>
<input name="address" type="text" value="
<?php
    if($_POST['submit']=='Update') {
		echo $_POST['address'];
	}
	else {
		echo $_GET['address'];
	}
?>
"><br>
<input name="submit" type="submit" value="Update"><br>
</form>
<?php

//建立資料連線物件
$pdo = new PDO("sqlite:mydb.sqlite");

$pdo->exec("CREATE TABLE address_book (
sid INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL ,
name VARCHAR,
phone VARCHAR,
address VARCHAR,
creation_date DATETIME DEFAULT CURRENT_TIMESTAMP)");

if( isset($_POST['submit']) && $_POST['submit']=='Update' ) {
    // 準備新增資料的語法
    $name = $_POST["name"];
    $phone = $_POST["phone"];
    $address = $_POST["address"];
	$pdo->exec("UPDATE 'address_book' SET name='$name', phone='$phone', address='$address' where sid=$_GET[sid]");
}

if( $_GET['op']=='del' ) {
// 準備刪除資料的語法
$pdo->exec("DELETE FROM 'address_book' WHERE
SID=$_GET[sid]");
}


$pdoStatement = $pdo->query("SELECT * FROM address_book");

/*
while($row = $pdoStatement->fetch() ) {
    print_r( $row );
}
*/
makeTable($pdoStatement);

function makeTable($pdoStatement)
{
	echo $_POST["sql"]."<br>";
	echo "<table border='1'>";
	//設定Title
	echo "<tr><td>sid</td>";
	echo "<td>name</td>";
	echo "<td>phone</td>";
	echo "<td>address</td>";
	echo "<td></td></tr>";
	//讀取內容
	while($row = $pdoStatement->fetch(PDO::FETCH_ASSOC) ) {
	echo "<tr><td>$row[sid]</td>";
	echo "<td>$row[name]</td>";
	echo "<td>$row[phone]</td>";
	echo "<td>$row[address]</td>";
	echo "<td><a href=add.php?op=del&sid=$row[sid]>del</a></td></tr>";
	}
	echo "</table>";
}





?>

add.php

<form action="" method="post" name="form1"><br>
Input address book data:<br>
<input name="name" type="text" value="shinder"><br>
<input name="phone" type="text" value="0918981520"><br>
<input name="address" type="text" value="Taipei"><br>
<input name="submit" type="submit" value="Add"><br>
</form>
<?php

//建立資料連線物件
$pdo = new PDO("sqlite:mydb.sqlite");

$pdo->exec("CREATE TABLE address_book (
sid INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL ,
name VARCHAR,
phone VARCHAR,
address VARCHAR,
creation_date DATETIME DEFAULT CURRENT_TIMESTAMP)");

if( isset($_POST['submit']) && $_POST['submit']=='Add' ) {
    // 準備新增資料的語法
    $name = $_POST["name"];
    $phone = $_POST["phone"];
    $address = $_POST["address"];
    $pdo->exec("INSERT INTO 'address_book' ('name', 'phone', 'address' )
    VALUES( '$name', '$phone', '$address')");
}

if( $_GET['op']=='del' ) {
// 準備刪除資料的語法
$pdo->exec("DELETE FROM 'address_book' WHERE
SID=$_GET[sid]");
}

if( $_GET['op']=='sort_sid' ) {
	$pdoStatement = $pdo->query("SELECT * FROM address_book order by sid desc");
}
else if( $_GET['op']=='sort_name' ) {
	$pdoStatement = $pdo->query("SELECT * FROM address_book order by name desc");
}
else {
	$pdoStatement = $pdo->query("SELECT * FROM address_book");
}

makeTable($pdoStatement);

function makeTable($temp)
{
	echo "<table border='1'>";
	//設定Title
	echo "<tr><td><a href=add.php?op=sort_sid>sid</a></td>";
	echo "<td><a href=add.php?op=sort_name>name</a></td>";
	echo "<td>phone</td>";
	echo "<td>address</td>";
	echo "<td></td>";
	echo "<td></td></tr>";
	//讀取內容
	while($row = $temp->fetch() ) {
	echo "<tr><td>$row[sid]</td>";
	echo "<td>$row[name]</td>";
	echo "<td>$row[phone]</td>";
	echo "<td>$row[address]</td>";
	echo "<td><a href=add.php?op=del&sid=$row[sid]>del</a></td>";
	echo "<td><a href=update.php?op=update&sid=$row[sid]&name=$row[name]&phone=$row[phone]&address=$row[address]>update</a></td></tr>";
	}
	echo "</table>";
}

?>

HW7_sample

# -*- coding: utf-8 -*-

# Form implementation generated from reading ui file 'test.ui'
#
# Created: Thu Jul 18 16:17:56 2013
#      by: PyQt4 UI code generator 4.10.1
#
# WARNING! All changes made in this file will be lost!

from PyQt4 import QtCore, QtGui

try:
    _fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
    def _fromUtf8(s):
        return s

try:
    _encoding = QtGui.QApplication.UnicodeUTF8
    def _translate(context, text, disambig):
        return QtGui.QApplication.translate(context, text, disambig, _encoding)
except AttributeError:
    def _translate(context, text, disambig):
        return QtGui.QApplication.translate(context, text, disambig)

class Ui_MainWindow(object):
    def setupUi(self, MainWindow):
        self.oper = ''
        self.num1=0
        self.num2=0
        MainWindow.setObjectName(_fromUtf8("MainWindow"))
        MainWindow.resize(357, 253)
        self.centralwidget = QtGui.QWidget(MainWindow)
        self.centralwidget.setObjectName(_fromUtf8("centralwidget"))
        self.lineEdit = QtGui.QLineEdit(self.centralwidget)
        self.lineEdit.setGeometry(QtCore.QRect(20, 20, 321, 41))
        self.lineEdit.setObjectName(_fromUtf8("lineEdit"))
        self.pushButton = QtGui.QPushButton(self.centralwidget)
        self.pushButton.setGeometry(QtCore.QRect(20, 100, 101, 41))
        font = QtGui.QFont()
        font.setFamily(_fromUtf8("Agency FB"))
        font.setPointSize(14)
        self.pushButton.setFont(font)
        self.pushButton.setObjectName(_fromUtf8("pushButton"))
        self.pushButton_2 = QtGui.QPushButton(self.centralwidget)
        self.pushButton_2.setGeometry(QtCore.QRect(20, 150, 101, 41))
        font = QtGui.QFont()
        font.setFamily(_fromUtf8("Agency FB"))
        font.setPointSize(14)
        self.pushButton_2.setFont(font)
        self.pushButton_2.setObjectName(_fromUtf8("pushButton_2"))
        self.pushButton_3 = QtGui.QPushButton(self.centralwidget)
        self.pushButton_3.setGeometry(QtCore.QRect(130, 100, 101, 41))
        font = QtGui.QFont()
        font.setFamily(_fromUtf8("Agency FB"))
        font.setPointSize(14)
        self.pushButton_3.setFont(font)
        self.pushButton_3.setObjectName(_fromUtf8("pushButton_3"))
        self.pushButton_4 = QtGui.QPushButton(self.centralwidget)
        self.pushButton_4.setGeometry(QtCore.QRect(130, 150, 101, 41))
        font = QtGui.QFont()
        font.setFamily(_fromUtf8("Agency FB"))
        font.setPointSize(14)
        self.pushButton_4.setFont(font)
        self.pushButton_4.setObjectName(_fromUtf8("pushButton_4"))
        self.pushButton_5 = QtGui.QPushButton(self.centralwidget)
        self.pushButton_5.setGeometry(QtCore.QRect(240, 100, 101, 41))
        font = QtGui.QFont()
        font.setFamily(_fromUtf8("Agency FB"))
        font.setPointSize(14)
        self.pushButton_5.setFont(font)
        self.pushButton_5.setObjectName(_fromUtf8("pushButton_5"))
        self.pushButton_6 = QtGui.QPushButton(self.centralwidget)
        self.pushButton_6.setGeometry(QtCore.QRect(240, 150, 101, 41))
        font = QtGui.QFont()
        font.setFamily(_fromUtf8("Agency FB"))
        font.setPointSize(14)
        self.pushButton_6.setFont(font)
        self.pushButton_6.setObjectName(_fromUtf8("pushButton_6"))
        MainWindow.setCentralWidget(self.centralwidget)
        self.menubar = QtGui.QMenuBar(MainWindow)
        self.menubar.setGeometry(QtCore.QRect(0, 0, 357, 22))
        self.menubar.setObjectName(_fromUtf8("menubar"))
        MainWindow.setMenuBar(self.menubar)
        self.statusbar = QtGui.QStatusBar(MainWindow)
        self.statusbar.setObjectName(_fromUtf8("statusbar"))
        MainWindow.setStatusBar(self.statusbar)

        self.retranslateUi(MainWindow)
        QtCore.QMetaObject.connectSlotsByName(MainWindow)
        QtCore.QObject.connect(self.pushButton, QtCore.SIGNAL("clicked()"), self.btn_add)
        QtCore.QObject.connect(self.pushButton_6, QtCore.SIGNAL("clicked()"), self.btn_equal)

    def retranslateUi(self, MainWindow):
        MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow", None))
        self.pushButton.setText(_translate("MainWindow", "+", None))
        self.pushButton_2.setText(_translate("MainWindow", "-", None))
        self.pushButton_3.setText(_translate("MainWindow", "*", None))
        self.pushButton_4.setText(_translate("MainWindow", "/", None))
        self.pushButton_5.setText(_translate("MainWindow", "C", None))
        self.pushButton_6.setText(_translate("MainWindow", "=", None))

    def btn_add(self):
        if self.num1 == 0:
            self.num1 = int(self.lineEdit.text())
        else:
            self.num1 = self.num1 + int(self.lineEdit.text())
            print(self.num1)
    def btn_equal(self):
        print(self.num1 + int(self.lineEdit.text()))

if __name__ == "__main__":
    import sys
    app = QtGui.QApplication(sys.argv)
    MainWindow = QtGui.QMainWindow()
    ui = Ui_MainWindow()
    ui.setupUi(MainWindow)
    MainWindow.show()
    sys.exit(app.exec_())

ASP.NET 連接 SQLite 範例

            //建立資料表
            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.CommandText = "INSERT INTO 'address_book' ('name', 'phone', 'address' ) VALUES('" + TextBox1.Text +"', '" + TextBox2.Text + "', '" + 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();