我需要帮助我在C#中找到一个这样的人。我不知道如何获取复选框的状态。我将发送代码,看看是否有人可以帮助我。我想在数据库中做一个插入,当我直接在数据库中测试它时,我的查询工作得很好,但现在我找不到解决这个问题的方法,如果有人能帮我的话就太好了。
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();
}
}
}
}
}
}发布于 2015-12-04 08:13:20
代替ThreeState
checkBoxUser.Checked.ToString();将返回"true“或"false”
发布于 2015-12-05 04:37:26
我将感谢大家的回答,但我实现了另一个解决方案,我认为这是更好的,因为在我的数据库中的表Puntoret(雇员)我有两个冒号是isUser和isAdmin结束这两个冒号在'bit‘数据类型返回true或false。我的实现在我写的查询中: checkBoxUser?'1‘'0’checkBoxAdmin?'1‘'0’
在我的“如果政治家”里没有checkBoxes。现在我从移动设备上回答你..当我将有我的笔记本电脑,我会发送完整的代码。但再次感谢你们所有人。
https://stackoverflow.com/questions/34074540
复制相似问题