我在Sqlite中为表添加约束如下:
using System.Windows;
using System.ComponentModel;
namespace WpfApplication1
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
BindingList<FamilyMember> Family = new BindingList<FamilyMember>();
public MainWindow()
{
InitializeComponent();
InitializeDG();
AddFamilyMembers();
}
private void InitializeDG()
{
dg_MainGrid.ItemsSource = Family;
dg_MainGrid.AutoGenerateColumns = true;
}
private void AddFamilyMembers()
{
Family.Add(new FamilyMember { FName = "Name1", LName = "D", Notes = "34" });
Family.Add(new FamilyMember { FName = "Name2", LName = "L", Notes = "36" });
Family.Add(new FamilyMember { FName = "Name3", LName = "D", Notes = "7" });
Family.Add(new FamilyMember { FName = "Name3", LName = "D", Notes = "5" });
}
private void button_Click(object sender, RoutedEventArgs e)
{
string TheName = ((FamilyMember)dg_MainGrid.SelectedItem).FName;//get the selected FName
}
}
public class FamilyMember
{
public string FName { get; set; }
public string LName { get; set; }
public string Notes { get; set; }
}
}
我在SQL Server数据库中使用此代码,但在SQLite中未被接受。
如何在Sqlite中创建这样的约束?
答案 0 :(得分:1)
SQLite3中的ALTER命令仅限于添加列或重命名表,因此您无法执行此操作。相反,您必须使用所需的约束重新创建表。