Hi, I have a combobox in my project. When i select any item from the combobox and click the submit button it have to store the selected item in a database
The combobox contains three items. For example red,blue,green. I will select any one item from the combobox and click the submit button. The selected item, for example if i select red, then the selected item should store in a database in my case its red.
Please Kindly Helpme...
Loading
arun kumarPosted Apr 13, 2012, 2:52 AM
Satyapriya NayakPosted Apr 12, 2012, 12:14 PM
Try this...
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 Combobox_access
{
public partial class Form1 : Form
{
string ConnectionString = System.Configuration.ConfigurationSettings.AppSettings["dsn"];
OleDbCommand com;
string str;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
comboBox1.Text = "Select";
comboBox1.Items.Add("Red");
comboBox1.Items.Add("Green");
comboBox1.Items.Add("Blue");
}
private void btn_insert_Click(object sender, EventArgs e)
{
OleDbConnection con = new OleDbConnection(ConnectionString);
con.Open();
str = "insert into test values('" + comboBox1.SelectedItem + "')";
com = new OleDbCommand(str, con);
com.ExecuteNonQuery();
con.Close();
MessageBox.Show("Records Successfuly Inserted");
}
}
}
Thanks
If this post helps you mark it as answer
SenthilkumarPosted Apr 12, 2012, 12:10 PM
First, you need to bind the combox box.
Then you need to write the code to get the selected value in the submit button.
In web.config file,
The above query has to be executed in the oledb connection in access database.