Hi friends,
I'm trying to send all data in my listbox
But in my Database shows as Follows
Name | StudyArea | Institue |
---|---|---|
aassa | ESOFT | |
aaaa | System.Windows.Forms.ListBox+ObjectCollection | ESOFT |
asela | System.Windows.Forms.ListBox+ObjectCollection | ESOFT |
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);
}
}