Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/314.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何从数据库c创建多年的下一个和上一个按钮#_C#_Mysql_.net - Fatal编程技术网

C# 如何从数据库c创建多年的下一个和上一个按钮#

C# 如何从数据库c创建多年的下一个和上一个按钮#,c#,mysql,.net,C#,Mysql,.net,我有一个用mysql数据库填充的组合框。 当用户从combobox中选择一个时间年时,我想在combobox附近创建两个按钮,然后我想单击按钮并移动到下一年 现在我有了这段代码,可以从DB获得年数 private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) { string command1 = "select year(Dat) FROM hydgod where Stat

我有一个用mysql数据库填充的组合框。 当用户从combobox中选择一个时间年时,我想在combobox附近创建两个按钮,然后我想单击按钮并移动到下一年

现在我有了这段代码,可以从DB获得年数

      private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
    {

        string command1 = "select year(Dat) FROM hydgod where Station=" + comboBox1.Text;

        MySqlDataAdapter da1 = new MySqlDataAdapter(command1, connection);
        DataTable dt1 = new DataTable();
        da1.Fill(dt1);

        comboBox2.Items.Clear();
        comboBox2.SelectedItem = -1;


        foreach (DataRow row in dt1.Rows)
        {
            string rowz = string.Format("{0}", row.ItemArray[0]);
            comboBox2.Items.Add(rowz);
            comboBox2.AutoCompleteCustomSource.Add(row.ItemArray[0].ToString());
        }
    }

如何从组合框中获取所选年份,并在下一年以+1递增,在上一年以-1递减?

请参见下面的代码了解上一个和下一个按钮

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication2
{
    public partial class Form1 : Form
    {
        int comboboxIndex = 0;
        public Form1()
        {
            InitializeComponent();

            comboBox1.Items.Clear();
            for (int i = 2000; i < 2018; i++)
            {
                comboBox1.Items.Add(i.ToString());
            }
            comboBox1.SelectedIndex = 0;
        }

        private void Previous_Click(object sender, EventArgs e)
        {
            if (comboboxIndex > 0)
            {
                comboboxIndex--;
                comboBox1.SelectedIndex = comboboxIndex;
            }

        }

        private void Next_Click(object sender, EventArgs e)
        {

            if (comboboxIndex < comboBox1.Items.Count - 1)
            {
                comboboxIndex++;
                comboBox1.SelectedIndex = comboboxIndex;
            }
        }
    }
}
使用系统;
使用System.Collections.Generic;
使用系统组件模型;
使用系统数据;
使用系统图;
使用System.Linq;
使用系统文本;
使用System.Windows.Forms;
命名空间Windows窗体应用程序2
{
公共部分类Form1:Form
{
int comboboxIndex=0;
公共表格1()
{
初始化组件();
comboBox1.Items.Clear();
对于(int i=2000;i<2018;i++)
{
comboBox1.Items.Add(i.ToString());
}
comboBox1.SelectedIndex=0;
}
私有无效上一次单击(对象发送者,事件参数e)
{
如果(comboboxIndex>0)
{
组合框索引--;
comboBox1.SelectedIndex=comboboxIndex;
}
}
私有无效下一次单击(对象发送者,事件参数e)
{
if(comboboxIndex