Get data from databaseAanuj11yAsked Jan 12, 2016, 7:18 PM ESTSolvedShareLinkedInXCopy linkSavehow to get a specific colum value from database ..with the combobox selction ..in window application form
Get data from databaseAanuj11yAsked Jan 12, 2016, 7:18 PM ESTSolvedShareLinkedInXCopy linkSavehow to get a specific colum value from database ..with the combobox selction ..in window application form
Arul RRank #2,478 · 566 reputation11y agoPosted Jan 12, 2016, 7:25 PM EST✓ Accepted answer0Kindly refer the below links, Hope this will solve your problem. http://www.codeproject.com/Questions/342593/How-we-display-database-table-one-column-values-in http://www.dreamincode.net/forums/topic/145973-fill-data-from-database-in-the-combobox/ http://www.codeproject.com/Articles/8597/Populate-data-from-database-in-a-ComboBox http://csharp.net-informations.com/dataset/dataset-combobox.htm http://dotnetsridhar.blogspot.in/2012/04/binding-combobox-in-windows.html Let me know for any thing more....If your problem solved means kindly Accept my answer0
Rajeesh MenothRank #118 · 18.4K reputation11y agoPosted Jan 12, 2016, 7:54 PM EST0Hi, using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Text;using System.Windows.Forms;using System.Data.SqlClient; namespace WindowsApplication44{ public partial class Form1 : Form { public Form1() { InitializeComponent(); } SqlDataAdapter da; DataSet ds = new DataSet(); private void Form1_Load(object sender, EventArgs e) { // Build the Connection String and create a SQL Connection object String cnnStr = "Data Source = localhost; Initial Catalog = Northwind; Integrated Security = SSPI"; SqlConnection cnn = new SqlConnection(cnnStr); // Create a SQL Command object from the connection object and setup the SELECT command SqlCommand cmd = cnn.CreateCommand(); cmd.CommandType = CommandType.Text; cmd.CommandText = "SELECT * FROM Customers"; // Create the data adapter to use to get the data and handle connecting to the DB da = new SqlDataAdapter(cmd); // Get the data from the database. I am using the Northwind database the customers table da.Fill(ds, "Customers"); // Disconnect the event handler to handle the comboBox1_SelectedIndexChanged event // while the combo box is being populated, otherwise it will fire a couple of times // before you are ready to handle them. this.comboBox1.SelectedIndexChanged -= new System.EventHandler(this.comboBox1_SelectedIndexChanged); // Connect the cobo box to the data source from where the data is comming from // In this case the Customers data table in the dataset. comboBox1.DataSource = ds.Tables["Customers"]; // Tell the combo box what collumn to display to the user comboBox1.DisplayMember = "CompanyName"; // Tell the combo box what collumn to use with the displayed value, value is not displayed comboBox1.ValueMember = "CustomerID"; // Restored the event handler this.comboBox1.SelectedIndexChanged += new System.EventHandler(this.comboBox1_SelectedIndexChanged); } private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) { // When the user clicks on a item in the combo box ist primary key will be displayed. MessageBox.Show("Customer Primary Key is \"" + comboBox1.SelectedValue + "\""); } }} Reference : http://www.codeproject.com/Questions/342593/How-we-display-database-table-one-column-values-in 0
Aanuj17 reputation11y agoPosted Jan 13, 2016, 8:41 PM EST0SqlCommand cmd = new SqlCommand("select id from customer where Name ='" +comboBox1.SelectedValue + "'", con); int anuj1 = Convert.ToInt32(cmd.ExecuteScalar()); i want id value from datatabel customer.. 0
Ranjit PowarRank #553 · 4.4K reputation11y agoPosted Jan 13, 2016, 8:46 PM EST0There is any error in your query?0
Manas MohapatraRank #182 · 13.2K reputation11y agoPosted Jan 13, 2016, 9:08 PM EST0Are you getting any exception after executing the code.0
Aanuj17 reputation11y agoPosted Jan 13, 2016, 10:15 PM EST0my table name is customer..and customer table colum name is id int,name varchar(20), and i bind the combobox with tha customer table ... i want id value from cutomer table with the selection of combobox try { con.Open(); SqlCommand cmd = new SqlCommand("select id from customer where Name ='" +comboBox1.SelectedValue + "'", con); int anuj1 = Convert.ToInt32(cmd.ExecuteScalar()); con.Close(); if (anuj1 > 0) { txtid.Text = Convert.ToString(anuj1); } } catch { }0Join to answer this questionEvery answer you publish earns 20 SHARP.Create free accountSign inKnow the answer?Answer a question in the forums and earn +20 SHARP for every answer.See unanswered questionsForumsTop experts01Arun PottiAnswers in the forums20answers02Tahir AnsariAnswers in the forums5answers03Kamlesh KumarAnswers in the forums5answers04Sam HobbsAnswers in the forums4answers05Željko PerićAnswers in the forums3answers?YouYour name goes here.Every answer: 20 SHARP.JoinFull leaderboard →2026DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Arul RRank #2,478 · 566 reputationPosted Jan 12, 2016, 7:25 PM EST
Rajeesh MenothRank #118 · 18.4K reputationPosted Jan 12, 2016, 7:54 PM EST
anuj17 reputationPosted Jan 13, 2016, 8:41 PM EST
Ranjit PowarRank #553 · 4.4K reputationPosted Jan 13, 2016, 8:46 PM EST
Manas MohapatraRank #182 · 13.2K reputationPosted Jan 13, 2016, 9:08 PM EST
anuj17 reputationPosted Jan 13, 2016, 10:15 PM EST
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questionsTop experts