mercredi 7 avril 2021

Not Showing CheckBox Data which added to the Database

I'm using visual studio windows form for the desktop app. I have several checkboxes in my form so I added them into one column but it isn't showing in the table leaving the column empty

AddWorks form

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace Ttable.Asram
{
    public partial class AddWorks : Form
    {
        //Database connection
        SqlConnection con = new SqlConnection(@"Data Source=DESKTOP-OGS07R8\SQLEXPRESS;Initial Catalog=TimeTable;Integrated Security=True");
        SqlCommand cmd;
        SqlDataAdapter adapt;

        //ID variable used in Updating and Deleting Record  
        int ID = 0;
        public AddWorks()
        {
            InitializeComponent();
        }

        private void AddWorks_Load(object sender, EventArgs e)
        {

        }

        private void AddW_Click(object sender, EventArgs e)
        {
            String s = "";
            foreach (Control c in this.Controls)
            {

                if (c is CheckBox)
                {

                    CheckBox b = (CheckBox)c;
                    if (b.Checked)
                    {
                        s = b.Text + "," + s;
                    }
                }
            }
            cmd = new SqlCommand("Insert into AddWorks1 (NWorkDay,Days,Hours)  values(@nDays,@Days,@hours)", con);
            con.Open();
            cmd.Parameters.AddWithValue("nDays", NWorkday.Text);
            cmd.Parameters.AddWithValue("@Days", s);
            cmd.Parameters.AddWithValue("@hours", TimeP.Text);

            cmd.ExecuteNonQuery();
            con.Close();
            MessageBox.Show("Record Inserted Successfully");
        }
    }
}


When I add this Code before it worked After Sometime I accidentally Deleted my full project and I restarted it that time it didn't worked

Table

Design




Aucun commentaire:

Enregistrer un commentaire