comBox绑定SQL Server数据库中时间字段中的不重复的年份

comBox绑定SQL Server数据库中时间字段中的不重复的年份

关于comBox绑定SQL Server数据库中时间字段中的不重复的年份如下:

private void Education_Training_Load(object sender, EventArgs e)

{

MyDBase DB = new MyDBase(DBUser.sserver, DBUser.DBName, DBUser.suser, DBUser.spasswd);

DataSet DS = DB.GetRecordset("select distinct (year(date)) as date from education_train ");

if (DS.Tables[0].Rows.Count == 0) return;

comboBox_Year.DataSource = DS.Tables[0];

comboBox_Year.DisplayMember = "date";

comboBox_Year.ValueMember = "date";

comboBox_Year.SelectedIndex = comboBox_Year.Items.Count - 1;//选中最大年份

if (DB.ErrorCode())

{

MessageBox.Show(DB.ErrMessage(), "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);

return;

}

dataGridView1.DataSource = DS.Tables[0];

DB.DBClose();

}