我已经学会了在我校学习指南这个LINQ代码,但他们不告诉我们在文本框中只有我们使用数据绑定属性,但我需要使用LINQ代码,而不是像我有组合框的数据进行显示。我怎样才能使用LINQ获取我的本地数据库数据以填充我的txt框?
public partial class Students : Form
{
LINQDataClasses1DataContext DB = new LINQDataClasses1DataContext();
public Students()
{
InitializeComponent();
}
private void Students_Load(object sender, EventArgs e)
{
//Retrieving data from datbaser using LINQ class convert it to list students ID's
var StudentIDs = (from c in DB.Students select c).ToList();
var STudentName = (from c in DB.Students select c).ToString();
//bind the Student ID combo box to database
cmbSTID.DataSource = StudentIDs;
//Databinding setup for the Student ID combo box
cmbSTID.DisplayMember = "SID";
cmbSTID.ValueMember = "SID";
cmbSTID.DataSource = StudentIDs;
你能否澄清你想要什么,实现什么到底是你的问题? –
也,你为什么设置数据源两次? – Kathi
对不起,我忘了删除第二个数据源。 –