?? form1.cs
字號:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlServerCe;
using System;
using System.IO;
namespace DeviceApplication2
{
public partial class Form1 : Form
{
SqlCeConnection conn;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button1_Click_1(object sender, EventArgs e)
{
try{
String constr = "Data Source = /My Documents/Test.sdf";
conn = new SqlCeConnection(constr);
conn.Open();
MessageBox.Show("Successful");
}catch (Exception ex){
MessageBox.Show(ex.ToString());
}
}
private void button2_Click(object sender, EventArgs e)
{
try
{
DataSet DS = new DataSet();
DataTable DT = new DataTable();
SqlCeDataAdapter DA = new SqlCeDataAdapter("select * from TestTable", conn);
DS.Clear();
DA.Fill(DS);
DT = DS.Tables[0];
dataGridShow.DataSource = DT;
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
private void button3_Click(object sender, EventArgs e)
{
try
{
SqlCeCommand sqlCmd = conn.CreateCommand();
//sqlCmd.CommandText = "insert into TestTable (T_int,T_var,T_bit)values(3,'3','1')";
sqlCmd.CommandText = "insert into TestTable (T_int,T_var,T_bit) values(@p1,@p2,@p3)";
SqlCeParameter p1 = new SqlCeParameter("@p1", Convert.ToInt32(T_int.Text));
SqlCeParameter p2 = new SqlCeParameter("@p2", T_var.Text);
SqlCeParameter p3 = new SqlCeParameter("@p3", Convert.ToInt32(T_bit.Text));
sqlCmd.Parameters.Add(p1);
sqlCmd.Parameters.Add(p2);
sqlCmd.Parameters.Add(p3);
sqlCmd.ExecuteNonQuery();
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
private void button4_Click(object sender, EventArgs e)
{
string rdaOleDbConnectString = "Provider=sqloledb; Data Source=mgm-win2003;Initial Catalog=BOS; User Id=pcms; Password = pcms";
SqlCeRemoteDataAccess rda = null;
try
{
rda = new SqlCeRemoteDataAccess();
rda.InternetLogin = "pcms";
rda.InternetPassword = "pcms";
rda.InternetUrl = "http://192.188.188.3/SQLCE/sqlcesa30.dll";
rda.LocalConnectionString = "Data Source= /My Documents/Test.sdf";
rda.Pull("TempTable", "Select * from TempTable", rdaOleDbConnectString, RdaTrackOption.TrackingOnWithIndexes, "ErrorTable");
MessageBox.Show("Successful");
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
MessageBox.Show(ex.Message);
}
}
private void button5_Click(object sender, EventArgs e)
{
string rdaOleDbConnectString = "Provider=sqloledb; Data Source=192.188.188.3;Initial Catalog=BOS; User Id=pcms; Password = pcms";
SqlCeRemoteDataAccess rda = null;
try
{
rda = new SqlCeRemoteDataAccess();
rda.InternetLogin = "pcms";
rda.InternetPassword = "pcms";
rda.InternetUrl = "http://192.188.188.3/SQLCE/sqlcesa30.dll";
rda.LocalConnectionString = "Data Source= /My Documents/Test.sdf";
rda.Push("TempTable", rdaOleDbConnectString);
MessageBox.Show("Successful");
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
private void button6_Click(object sender, EventArgs e)
{
try
{
string path = @"/My Documents/Test.sdf";
File.Delete(path);
SqlCeEngine engine = new SqlCeEngine("Data Source='/My Documents/Test.sdf';");
engine.CreateDatabase();
MessageBox.Show("Succesful");
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -