一起和新手朋友學習一下WinCE下對數據庫的操作方法
using System;
using System
using System
using System
using System
using System
using System
using System
using System
using System
namespace ReadSDFFileOnDesktop
{
public partial class MainForm : Form
{
public static string strSQLPath =
public static string strConString =
public static string strAccessString =
public MainForm()
{
InitializeComponent();
}
private void buttonCreateDB_Click(object sender
{
// 創建數據庫
if (File
{
// 刪除數據庫
File
CreateDataBase();
}
else
{
// 創建數據庫
CreateDataBase();
}
}
private void CreateDataBase()
{
// 創建數據庫文件
SqlCeEngine engine = new SqlCeEngine(strConString);
engine
engine
MessageBox
}
private void buttonCreateTable_Click(object sender
{
if (File
{
// 創建表
SqlCeConnection cn = new SqlCeConnection(strConString);
cn
try
{
string strSQL = @
fname nvarchar(
job_id nvarchar(
hire_date datetime)
SqlCeCommand SqlCeCmd = new SqlCeCommand(strSQL
SqlCeCmd
MessageBox
}
catch (SqlCeException ex)
{
MessageBox
}
finally
{
cn
}
}
else
{
MessageBox
}
}
private void buttonImportData_Click(object sender
{
// 導入數據
OleDbConnection OleDbCn = new OleDbConnection(strAccessString);
try
{
OleDbCn
OleDbCommand OleDbCmd = new OleDbCommand(
OleDbDataReader OleDbDr = OleDbCmd
SqlCeConnection SqlCeCn = new SqlCeConnection(strConString);
try
{
SqlCeCn
SqlCeCommand SqlCeCmd = new SqlCeCommand();
SqlCeCmd
while (OleDbDr
{
string strSQL =
strSQL = String
VALUES (
OleDbDr
OleDbDr
OleDbDr
OleDbDr
OleDbDr
OleDbDr
OleDbDr
OleDbDr
SqlCeCmd
SqlCeCmd
}
MessageBox
}
catch (SqlCeException ex)
{
MessageBox
}
finally
{
SqlCeCn
}
}
catch (OleDbException ex)
{
MessageBox
}
finally
{
OleDbCn
}
}
private void buttonShowData_Click(object sender
{
// 顯示數據
SqlCeConnection SqlCeCn = new SqlCeConnection(strConString);
try
{
SqlCeCn
string strSQL =
strSQL = String
SqlCeCommand SqlCeCmd = new SqlCeCommand(strSQL
SqlCeDataReader SqlCeDr = SqlCeCmd
listView
while (SqlCeDr
{
ListViewItem item;
item = new ListViewItem(SqlCeDr
(SqlCeDr
item
GetOrdinal(
item
GetOrdinal(
item
GetOrdinal(
item
item
GetOrdinal(
item
GetOrdinal(
item
GetOrdinal(
listView
}
}
catch (SqlCeException ex)
{
MessageBox
}
finally
{
SqlCeCn
}
}
}
}
From:http://tw.wingwit.com/Article/program/net/201311/13452.html