i need to help me someone this checkboxs in C#. I don't know how to get the state of the check box. I will send the code to see if someone can help me with this. I want to make an Insert in the database, my query work pretty well when i test it directly in the database, and now I can't find solution for this, if any one can help me will be great.
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();
}
}
}
}
}
}