關於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();
}