** install SQLiteStudio: Download

** open project (already success by using SQL server)

** add reference: System.Data.SQLite & System.Data.SQLite.Linq

** test code: from ROACH (create new project, to make sure that SQLite can run in successfully)

** open SQLiteStudio, browse db (DataBase) from : project path\project's name\project's name\bin\ (here)

the file may be named by database.db

** use SQLiteStudio to add/delete/view/search(?) data

** create a new database for the original project (run with SQL server)

create the same table as the .mdf(SQL server file)

** using "ROACH"'s code the edit project, complete project and run successfully by SQLite

 


 how to creat a new database:

** open SQLiteStudio

** (LeftTop) Databases >> Add database >> Database file (browse the destination, and press the databese file NAME.db)

Click "OK"

** Right-click "tables" >> New Table

press all the table's detail

EX: Table Name > member

(click "Add column")

Column Name> ID , Type> char, Size> 20

(click "primary key" : ID can't have two same one)

(click "Not Null": ID can't be Null)

click "Create"

...

Fill the table untill all the item was be press

** memeber >> Data >> Add new row(insert) : create the data fot search the database to make sure the SQLite can work

** Create all the table and fill all the default data you need!

 


 test the new database can be use, Code:

using System.Data.SQLite;

namespace SQLITE
{

public partial class Form1 : Form
{

private SQLiteConnection sqlite_conn;
private SQLiteCommand sqlite_cmd;

public Form1()
{
InitializeComponent();
}

private void button0_Click(object sender, EventArgs e)
{

sqlite_conn = new SQLiteConnection("Data source=DailyRecord.db");

sqlite_conn.Open();

sqlite_cmd = sqlite_conn.CreateCommand();

sqlite_cmd.CommandText = "SELECT * FROM member";

SQLiteDataReader sqlite_datareader = sqlite_cmd.ExecuteReader();

while (sqlite_datareader.Read())
{

String s = sqlite_datareader["ID"].ToString();
String s2 = sqlite_datareader["password"].ToString();
MessageBox.Show("ID:"+s+"\nPassword:"+s2);
}

sqlite_conn.Close();

 }

}

}


if framework4.0 can't work SQLite

** add reference: System.Data.SQLite & System.Data.SQLite.Linq

** open app.config, add/change <startup> code:

<configuration>

<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0"/>
</startup>

</configuration>

創作者介紹

Mi-t'ao

Yixue 發表在 痞客邦 PIXNET 留言(0) 人氣()