Quantcast
Channel: Windows Forms Data Controls and Databinding forum
Viewing all articles
Browse latest Browse all 2535

how send all list items in listbox to access database in c#

$
0
0

Hi friends,

I'm trying to send all data in my listbox


But in my Database shows as Follows

<tfoot></tfoot>
TableName
NameStudyAreaInstitue
aassa
ESOFT
aaaaSystem.Windows.Forms.ListBox+ObjectCollectionESOFT
aselaSystem.Windows.Forms.ListBox+ObjectCollectionESOFT

i used cording of this

public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        System.Data.OleDb.OleDbConnection conn;
        System.Data.OleDb.OleDbCommand comm;
        private void button1_Click(object sender, EventArgs e)
        {
            string ins;
            if (radioButton1.Checked == true)
            { ins = radioButton1.Text; }
            else
            { ins = radioButton2.Text; }
            string connectionString, commandString;
            connectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:/Lessons/C#/list/DatabaseName.accdb";
            commandString = "INSERT INTO TableName VALUES('" + textBox1.Text + "','"+listBox1.Items.ToString()+"','"+ins+"')";
            conn = new System.Data.OleDb.OleDbConnection(connectionString);
            comm = new System.Data.OleDb.OleDbCommand(commandString, conn);
            conn.Open();
            comm.ExecuteNonQuery();
            MessageBox.Show("Record Added successfully");
            conn.Close();
        }

        private void checkBox1_CheckedChanged(object sender, EventArgs e)
        {
            listBox1.Items.Add(checkBox1.Text);
        }

        private void checkBox2_CheckedChanged(object sender, EventArgs e)
        {
            listBox1.Items.Add(checkBox2.Text);
        }

        private void checkBox3_CheckedChanged(object sender, EventArgs e)
        {
            listBox1.Items.Add(checkBox3.Text);
        }

        private void checkBox4_CheckedChanged(object sender, EventArgs e)
        {
            listBox1.Items.Add(checkBox4.Text);
        }

       
    }


Viewing all articles
Browse latest Browse all 2535

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>