我需要幫助我這個C#中的複選框。我不知道如何獲取複選框的狀態。我會發送代碼,看看是否有人可以幫助我。我想在數據庫中創建一個Insert,當我直接在數據庫中測試它時,我的查詢工作得很好,現在我找不到解決方案,如果有人能幫助我,那將會很棒。獲取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();
}
}
}
}
}
}
除了想知道爲什麼你要添加新的臀部「僱員」,在哪裏試圖讀取複選框的狀態?對接移植手術? –
使用'Checked'屬性?即'checkBox1.Checked'。選中時返回「true」,未選中時返回「false」。 –
'Checked'屬性就是你要找的[ToggleButton.IsChecked](https://msdn.microsoft.com/en-us/library/system.windows.controls.primitives.togglebutton.ischecked(v = vs。 110).aspx) – AWinkle