C# combox控件向数据库里添加数据的功能

问题遇到的现象和发生背景

写了一个页面,类似于人事管理,想要实现combox下拉框向数据库中添加数据的功能,之前写过text控件向数据库里面添加数据的,头一次遇到combox控件,我的界面类似如下,我不太清楚第一个的日期如何添加进数据库里,数据库本来就有一列是专门给日期准备的

img

我想要达到的结果

combox控件里的下拉框内容可以添加到数据库里面

获取DateTimePicker和ComboBox的

效果如下:

img

示例代码如下:

namespace WinFormsApp1
{
    public partial class Form2 : Form
    {
        public Form2()
        {
            InitializeComponent();
        }

        private void btnCreate_Click(object sender, EventArgs e)
        {
            var message = $"你选择的工作时间为:{dateWorkingTime.Value.ToLongDateString()},人员来源(Value):{cboxSource.SelectedValue},人员来源(Text):{cboxSource.Text}";
            MessageBox.Show(message);
        }

        private void Form2_Load(object sender, EventArgs e)
        {
            var sources = new List<Source>
            {
                new Source{Value = 1,Text ="线上"},
                new Source{Value = 2,Text ="线下"}
            };
            cboxSource.DataSource = sources;
            cboxSource.ValueMember = "Value";
            cboxSource.DisplayMember = "Text";
        }
    }

    public class Source
    {
        public int Value { get; set; }
        public string Text { get; set; }
    }
}