小编Phi*_*mon的帖子

如何将boolean绑定到组合框

我遇到了有关数据库和组合框的问题.我有一个表名"站",表内有列,站名和座位.柱座设置为"BIT".我使用组合框为用户选择"是"或"否",但如何将它们转换为BIT并存储到数据库中.这是我创建的代码.

private void btnCreate_Click(object sender, EventArgs e)
    {
        using (testEntities Setupctx = new testEntities())
        {
            string[] stations = StationNameList();
            station creStation = new station();
            creStation.Station1 = txtStation.Text;
            creStation.Seat = cbSeats.SelectedItem();
            if (stations.Contains(txtStation.Text))
            {
                MessageBox.Show("This Station is already been created. Please enter a new Station.");
            }
            else
            {
                Setupctx.stations.AddObject(creStation);
                Setupctx.SaveChanges();
                txtStation.Text = "";
                cbSeats.SelectedIndex = -1;
                MessageBox.Show("New Station Has Been Created.");
            }
        }
    }
Run Code Online (Sandbox Code Playgroud)

错误发生在这里:

creStation.Seat = cbSeats.SelectedItem();
Run Code Online (Sandbox Code Playgroud)

他们提示我无法从字符串转换为bool.有帮助吗?

c# linq combobox boolean

3
推荐指数
1
解决办法
1659
查看次数

删除信息后自动更新主键

有谁知道如何解决这个ID问题?

例如 :

ID | Message
1  |  Hi
2  |  Philemon
3  |  Car              <-- Delete this row
4  |  Tay
5  |  Bye
Run Code Online (Sandbox Code Playgroud)

删除第3行时,行后的ID将自动更新并填写ID.

ID  | Message
1   | Hi
2   | Philemon
3   | Tay
4   | Bye
Run Code Online (Sandbox Code Playgroud)

更多信息 :

private void btnDel_Click(object sender, EventArgs e)
    {
        using (testEntities Setupctx = new testEntities())
        {
            int ID = Int32.Parse(lblID.Text);
            var DeleteSh = (from delsh in Setupctx.shifthours
                            where delsh.idShiftHours == ID
                            select delsh).Single();
            Setupctx.DeleteObject(DeleteSh);
            Setupctx.SaveChanges();
            txtStart.Text = "";
            txtStop.Text …
Run Code Online (Sandbox Code Playgroud)

c# mysql linq primary-key

-2
推荐指数
1
解决办法
1060
查看次数

标签 统计

c# ×2

linq ×2

boolean ×1

combobox ×1

mysql ×1

primary-key ×1