เป็นTool สำเร็จรูปสำหรับ การ ทำงานกับ SQLite
https://www.dropbox.com/s/dm7y1t3pthj0et5/PPSqlLite.dll.7z?dl=0
ตัวอย่างวิธีใช้
/*
* Created by SharpDevelop.
* User: mcad
* Date: 11/7/2015
* Time: 1:16 PM
*
* To change this template use Tools | Options | Coding | Edit Standard Headers.
*/
using System;
using System.Collections;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
using PPSqlLite;
namespace db1
{
/// <summary>
/// Description of MainForm.
/// </summary>
public partial class MainForm : Form
{
public MainForm()
{
//
// The InitializeComponent() call is required for Windows Forms designer support.
//
InitializeComponent();
//
// TODO: Add constructor code after the InitializeComponent() call.
//
}
void Button1Click(object sender, EventArgs e)
{ // การอ่าน Data
PPSQLLite mysql = new PPSQLLite();
mysql.setSqlDataFile(@"c:\CAADDB\data.db");
ArrayList list1 =mysql.getAColSql("select name from customer");
listBox1.Items.Clear();
foreach(string astr in list1)
{
listBox1.Items.Add(astr);
}
}
void ListBox1SelectedIndexChanged(object sender, EventArgs e)
{
PPSQLLite mysql = new PPSQLLite();
mysql.setSqlDataFile(@"c:\CAADDB\data.db");
ArrayList list1 =mysql.getAColSql("select phone from customer where name='"
+listBox1.SelectedItem.ToString()+"'");
if(list1!=null && list1.Count>0)
{
MessageBox.Show(list1[0].ToString());
}
}
void Button2Click(object sender, EventArgs e)
{ // การ Insert ใหม่ และ เช็คข้อมูลเก่า
PPSQLLite mysql = new PPSQLLite();
mysql.setSqlDataFile(@"c:\CAADDB\data.db");
ArrayList list1 =mysql.getAColSql("select max(id)+1 from customer");
if(list1!=null && list1.Count>0)
{
label1.Text=list1[0].ToString();
}
string sqlIns="insert into customer values ("+
// insert field here
label1.Text +","+ // id
"'"+textBox1.Text +"',"+ // name
"'"+textBox2.Text +"',"+ // surname
textBox3.Text+","+ // age
"'"+textBox4.Text +"',"+ // phone
textBox5.Text // salary
+")";
// protect double click
ArrayList list2 = mysql.getAColSql("select name from customer where name='"+textBox1.Text+"'");
if(list2!=null && list2.Count>0)
{
MessageBox.Show("Already Exist");
}
else{
mysql.ExecuteQuery(sqlIns);
}
}
}
}