📄 northwinddata.cs
字号:
using System;
using System.Text;
using System.Windows.Forms;
using System.Data;
using System.Data.SqlServerCe;
namespace Microsoft.Sql.SqlCe.Samples.Cs.NorthwindCe {
/// <summary>
/// Summary description for NorthwindData.
/// </summary>
internal class NorthwindData {
static NorthwindData northwind = null;
private readonly string localDatabaseFile;
private readonly string localConnString;
private SqlCeConnection cnNorthwind;
private DataSet dsNorthwind;
private NorthwindData() {
localDatabaseFile = @"My Documents\NorthwindDemo.sdf";
// Construct the local connecting string.
//
localConnString = @"Data Source= " + localDatabaseFile;
cnNorthwind = new SqlCeConnection(localConnString);
dsNorthwind = new DataSet("Northwind");
}
~NorthwindData() {
}
public SqlCeConnection NorthwindConnection {
get {
return cnNorthwind;
}
}
public DataSet NorthwindDataSet {
get {
return dsNorthwind;
}
}
public string LocalDatabaseFile {
get {
return localDatabaseFile;
}
}
public string LocalConnString {
get {
return localConnString;
}
}
public static NorthwindData GetInstance() {
if (null == northwind)
northwind = new NorthwindData();
return northwind;
}
public void Close() {
if (ConnectionState.Open == cnNorthwind.State) {
cnNorthwind.Close();
}
}
internal static void ShowErrors(SqlCeException e) {
// Show SQL Server CE error information.
//
SqlCeErrorCollection errorCollection = e.Errors;
StringBuilder bld = new StringBuilder();
Exception inner = e.InnerException;
if (null != inner) {
MessageBox.Show("Inner Exception: " + inner.ToString(), "Northwind");
}
foreach (SqlCeError err in errorCollection) {
bld.Append("\n Error Code: " + err.HResult.ToString("X"));
bld.Append("\n Message : " + err.Message);
bld.Append("\n Minor Err.: " + err.NativeError);
bld.Append("\n Source : " + err.Source);
foreach (int numPar in err.NumericErrorParameters) {
if (0 != numPar) bld.Append("\n Num. Par. : " + numPar);
}
foreach (string errPar in err.ErrorParameters) {
if (String.Empty != errPar) bld.Append("\n Err. Par. : " + errPar);
}
MessageBox.Show(bld.ToString(), "Northwind");
bld.Remove(0, bld.Length);
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -