Combox a non-repeating year in a Time field in a SQL Server database binding

Source: Internet
Author: User

About the Combox binding SQL Server database The time fields are not duplicates in the following years:

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 (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;//Select the maximum year

if (DB. ErrorCode ())


MessageBox.Show (DB. Errmessage (), "hint", MessageBoxButtons.OK, Messageboxicon.error);



Datagridview1.datasource = DS. Tables[0];

Db. Dbclose ();


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.