Save check-box-list values to database (windows application)

Posted by Chaithragm under C# on 3/27/2013 | Points: 10 | Views : 7851 | Status : [Member] | Replies : 2
I want to save multiple check-box-list values in one column of the database. I want to save the values to database. Please Help ME..... And also I want Display the values from database....
languages ->column in the data base
i have used checkbox list -contians three checkboxes kannada,English,Hindi
where i can select any one or all




Responses

Posted by: Jayakumars on: 3/27/2013 [Member] [MVP] Bronze | Points: 25

Up
0
Down
hi

refer this

http://social.msdn.microsoft.com/Forums/en-US/winforms/thread/da3523f6-4b48-45ba-8131-635596268bb7/

Mark as Answer if its helpful to you

Chaithragm, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Satyapriyanayak on: 3/27/2013 [Member] [MVP] Silver | Points: 25

Up
0
Down
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
namespace InsertmultipleValueCheckBoxList
{
public partial class Form1 : Form
{
string ConnectionString = System.Configuration.ConfigurationSettings.AppSettings["dsn"];
OleDbCommand com;

public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{
checkedListBox1.Items.Add("kannada");
checkedListBox1.Items.Add("English");
checkedListBox1.Items.Add("Hindi ");
}

private void btn_insert_Click(object sender, EventArgs e)
{
OleDbConnection con = new OleDbConnection(ConnectionString);
foreach (var checkedItem in this.checkedListBox1.CheckedItems)
{
com = new OleDbCommand("Insert into test values('" + checkedItem + "')", con);
con.Open();
com.ExecuteNonQuery();
con.Close();
}
MessageBox.Show("Inserted Successfully");
}
}
}


If this post helps you mark it as answer
Thanks

Chaithragm, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response