📄 joinqueryresultsetform.cs
字号:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlServerCe;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace MobileDevelopersHandbook
{
public partial class JOINQueryResultSetForm : Form
{
public JOINQueryResultSetForm()
{
InitializeComponent();
}
private void JOINQueryResultSetForm_Load(object sender, EventArgs e)
{
try
{
// Create an instance of the typed SqlCeResultSet
JoinQueryResultSetResultSets.ProductsCategoryResultSet set =
new JoinQueryResultSetResultSets.ProductsCategoryResultSet();
}
catch (SqlCeException sqlEx)
{
MessageBox.Show("The default Constructor created by the tools does not work with"
+ " a complex query. Message: " + sqlEx.Message + "\r\nPress OK to continue.");
}
string connectionString = "Data Source ="
+ (System.IO.Path.GetDirectoryName(System.Reflection.
Assembly.GetExecutingAssembly().GetName().CodeBase)
+ "\\MyDatabase.sdf\\; Password =\"MobileP@ssw0rd\";");
// Create an instance using our own constructor - don't open it yet
JoinQueryResultSetResultSets.ProductsCategoryResultSet rsltSet =
new JoinQueryResultSetResultSets.ProductsCategoryResultSet(false, connectionString);
// Define the query
string query = "SELECT Product.ProductID, Product.Name, Product.Color,"
+ "Product.ListPrice, Product.Size, ProductCategory.Name AS CategoryName "
+ "FROM Product, ProductCategory "
+ "WHERE Product.ProductCategoryID = ProductCategory.ProductCategoryID";
// Open it, and supply our query
rsltSet.Open(query);
// List the results in a ListView
while (rsltSet.Read())
{
// Simple list in the format: <product name> - <product category mame>
listView1.Items.Add(new ListViewItem(rsltSet.Name + " - " + rsltSet.CategoryName));
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -