⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 form1.cs

📁 将带您了解SQL Server Compact 3.5的发展历程和功能特性
💻 CS
字号:
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlServerCe;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Windows.Forms;
using System.Xml.Linq;

namespace SQLceISAM
{
	public partial class Form1
	{
		#region Default Instance
		
		private static Form1 defaultInstance;
		
		/// <summary>
		/// Added by the VB.Net to C# Converter to support default instance behavour in C#
		/// </summary>
		public static Form1 Default
		{
			get
			{
				if (defaultInstance == null)
				{
					defaultInstance = new Form1();
					defaultInstance.FormClosed += new FormClosedEventHandler(defaultInstance_FormClosed);
				}
				
				return defaultInstance;
			}
		}
		
		static void defaultInstance_FormClosed(object sender, FormClosedEventArgs e)
		{
			defaultInstance = null;
		}
		
		#endregion

		private SqlCeConnection _conn;
		
		private void Form1_Load(System.Object sender, System.EventArgs e)
		{
			_conn.Open();
			LoadIndexList();
		}
		
		private void LoadIndexList()
		{
			// Populate the IndexListBox with the list of indexes available
			SqlCeCommand cmd = new SqlCeCommand();
			cmd.Connection = _conn;
			cmd.CommandText = "SELECT INDEX_NAME FROM INFORMATION_SCHEMA.INDEXES " + "WHERE TABLE_NAME = \'Customers\' " + "AND PRIMARY_KEY = 1 " + "OR ([UNIQUE] = 0 AND PRIMARY_KEY= 0) " + "GROUP BY INDEX_NAME " + "ORDER BY INDEX_NAME ";
			this.IndexBindingSource.DataSource = cmd.ExecuteResultSet(ResultSetOptions.Scrollable);
			this.IndexListBox.DisplayMember = "INDEX_NAME";
		}
		
		private void IndexListBox_SelectedIndexChanged(System.Object sender, System.EventArgs e)
		{
			if (IndexListBox.SelectedIndex >= 0)
			{
				LoadTableData();
			}
		}
		
		private void LoadTableData()
		{
			// Based on the selected index, open a cursort directly against the table
			SqlCeCommand cmd = new SqlCeCommand();
			cmd.Connection = _conn;
			cmd.CommandText = "Customers";
			cmd.CommandType = CommandType.TableDirect;
			
			// This bypasses the query processor
			//TODO: Set the Index
			cmd.IndexName = this.IndexListBox.Text;
			this.BindingSource1.DataSource = cmd.ExecuteResultSet(ResultSetOptions.Scrollable | ResultSetOptions.Updatable);
		}
		
		public Form1()
		{
			InitializeComponent();
			
			//Added to support default instance behavour in C#
			if (defaultInstance == null)
				defaultInstance = this;
			_conn = new SqlCeConnection("Data Source = |DataDirectory|\\LocalDatabase.sdf");
			this.IndexListBox.DataSource = this.IndexBindingSource;
			this.DataGridView1.AutoGenerateColumns = true;
		}
		
		private void Form1_Disposed(object sender, System.EventArgs e)
		{
			_conn.Dispose();
		}
	}
	
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -