首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在C#中获取复选框状态的问题

在C#中获取复选框状态的问题
EN

Stack Overflow用户
提问于 2015-12-04 03:30:04
回答 2查看 76关注 0票数 1

我需要帮助我在C#中找到一个这样的人。我不知道如何获取复选框的状态。我将发送代码,看看是否有人可以帮助我。我想在数据库中做一个插入,当我直接在数据库中测试它时,我的查询工作得很好,但现在我找不到解决这个问题的方法,如果有人能帮我的话就太好了。

代码语言:javascript
复制
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace Program_Sistem_Menaxhimi_Per_Gjykatat
{
    public partial class AddNewEmploee : Form
    {
        public AddNewEmploee()
        {
            InitializeComponent();
        }

        private void label3_Click(object sender, EventArgs e)
        {

        }

        private void createUserAddNewEmploeeButt_Click(object sender, EventArgs e)
        {

        }

        private void confirmAddNewEmploeeButt_Click(object sender, EventArgs e)
        {
            string connectionString = @"Data Source=fp-PC;Initial Catalog=Gjykata;Integrated Security=True";//Connection String
            string sqlcommand = "insert into Puntoret (emri,mbiemri,adresa,telefoni,id_profesionit,isUser,isAdmin,username,passWord) values ('" + emriTextBox.Text + "','" + mbiemriTxtBox.Text + "','" + adresaTxtBox.Text + "','" + telefoniTxtBox.Text + "','" + idEProfTxtBox.Text + "','" + checkBoxUser.ThreeState.ToString() + "','" + checkBoxAdmin.ThreeState.ToString() + "','" + usernameTxtBox.Text + "','" + passwordTxtBox.Text + "')";//Sql command
            SqlConnection connection = new SqlConnection(connectionString);//Creating new Sql Connetion

            if(emriTextBox.Text != "" && mbiemriTxtBox.Text != "" && adresaTxtBox.Text != "" && telefoniTxtBox.Text != "" && idEProfTxtBox.Text != "" && checkBoxUser.ThreeState.ToString() != "False" && checkBoxAdmin.ThreeState.ToString() != "False" && usernameTxtBox.Text != "" && passwordTxtBox.Text != "")
            {
                using (SqlCommand command = new SqlCommand(sqlcommand))
                {
                    command.Connection = connection;
                    command.CommandText = sqlcommand;
                    command.CommandType = CommandType.Text;

                    try
                    {
                        connection.Open();
                        command.ExecuteNonQuery();
                    }
                    finally
                    {
                        connection.Close();
                    }
                }
            }

        }
    }
}
EN

回答 2

Stack Overflow用户

发布于 2015-12-04 08:13:20

代替ThreeState

代码语言:javascript
复制
checkBoxUser.Checked.ToString();

将返回"true“或"false”

票数 2
EN

Stack Overflow用户

发布于 2015-12-05 04:37:26

我将感谢大家的回答,但我实现了另一个解决方案,我认为这是更好的,因为在我的数据库中的表Puntoret(雇员)我有两个冒号是isUser和isAdmin结束这两个冒号在'bit‘数据类型返回true或false。我的实现在我写的查询中: checkBoxUser?'1‘'0’checkBoxAdmin?'1‘'0’

在我的“如果政治家”里没有checkBoxes。现在我从移动设备上回答你..当我将有我的笔记本电脑,我会发送完整的代码。但再次感谢你们所有人。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/34074540

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档