您现在的位置: 万盛学电脑网 >> 程序编程 >> 数据库 >> mysql教程 >> 正文

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

作者:佚名    责任编辑:admin    更新时间:2022-06-22

   关于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();

  }