473,326 Members | 2,076 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

How to get data from combo box?

Pls could anyone help me how to get data from combo box with my following code

i used txt_app_code for combo box name.

Expand|Select|Wrap|Line Numbers
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9.  
  10. namespace WindowsFormsApplication8
  11. {
  12.  
  13.     public partial class frm_Application_Details : Form
  14.     {
  15.         public ADODB.Connection con = new ADODB.Connection();
  16.         public ADODB.Recordset rs = new ADODB.Recordset();
  17.         public string ConStr;
  18.         public string db_Server;
  19.         public string db_port;
  20.         public string db;
  21.         public string db_User;
  22.         public string db_Pass;
  23.         public string query;
  24.  
  25.  
  26.         public frm_Application_Details()
  27.         {
  28.             InitializeComponent();
  29.         }
  30.  
  31.  
  32.  
  33.  
  34.         private void button2_Click(object sender, EventArgs e)
  35.         {
  36.             if (txt_App_Code.Text == "")
  37.             {
  38.                 MessageBox.Show("Please Enter the Application Code");
  39.                 return;
  40.             }
  41.             if (txt_App_Name.Text == "") { MessageBox.Show("Please Enter the name"); return; }
  42.             if (txt_Start_Date.Text == "") { MessageBox.Show("Please Enter the Date and Time"); return; }
  43.  
  44.             query = "select * from application_m where ApplicationCode='" + txt_App_Code.Text + "'";
  45.             rs.Open(query, con, ADODB.CursorTypeEnum.adOpenKeyset, ADODB.LockTypeEnum.adLockOptimistic, -1);
  46.             if (rs.EOF == false)
  47.             {
  48.                 rs.Close();
  49.                 MessageBox.Show("Application Code is Already used. Please Enter Different Application code");
  50.                 return;
  51.             }
  52.             else
  53.             {
  54.                 rs.Close();                
  55.                 query = "Insert Into application_m(ApplicationCode,ApplicationName,StartDate) Values('" + txt_App_Code.Text + "','" + txt_App_Name.Text + "',now())";
  56.                 rs.Open(query, con, ADODB.CursorTypeEnum.adOpenKeyset, ADODB.LockTypeEnum.adLockOptimistic, -1);
  57.                 MessageBox.Show("Application details saved");
  58.             }
  59.         }
  60.  
  61.  private void frm_Application_Details_Load(object sender, EventArgs e)
  62.         {
  63.             db_Server = "localhost";
  64.             db_port = "3306";
  65.             db = "etechdata";
  66.             db_User = "root";
  67.             db_Pass = "";
  68.             ConStr = "DRIVER={MySQL ODBC 3.51 Driver};SERVER=" + db_Server + ";PORT=" + db_port + ";DATABASE=" + db + ";UID=" + db_User + ";PWD=" + db_Pass + ";OPTION=3";
  69.             //OdbcCon.ConnectionString = ConStr;
  70.          try
  71.             {
  72.  
  73.                 con.Open(ConStr, null, null, 0);
  74.  
  75.             }
  76.             catch (System.Data.Odbc.OdbcException Ex)
  77.             {
  78.  
  79.                 MessageBox.Show("Could not access the database.\r\nPlease make sure you completed the fields with the correct information and try again.\r\n\r\nMore details:\r\n" + Ex.Message, "Database connection error", MessageBoxButtons.OK, MessageBoxIcon.Error);
  80.             }
  81.         }
  82.  
  83.  
Jul 23 '10 #1
3 5512
GaryTexmo
1,501 Expert 1GB
I don't understand your question... what data do you need to get? You're already calling txt_App_Code.Text to get the currently selected item.

Do you need something else? Please be more specific about your question.
Jul 23 '10 #2
Hi gary tnx for replying me..

i need to get the data from database and populate in the combo box.
Jul 24 '10 #3
Leito
58
Here is how I retrieve data from my database to populate the comboBox:
Expand|Select|Wrap|Line Numbers
  1. // Set query to retrieve clients
  2. String query = "SELECT id, name FROM tblClients";
  3. // Execute query
  4. SqlDataAdapter clientsDA = new SqlDataAdapter(query, database_con);
  5. // Fill dataset
  6. DataSet clientsDS = new DataSet();
  7. clientsDA.Fill(clientsDS);
  8. // Add clients list to the comboBox
  9. this.comboBoxClients.DataSource = clientsDS.Tables[0];
  10. this.comboBoxClients.DisplayMember = "name";
  11. this.comboBoxClients.ValueMember = "id";
  12.  
Aug 2 '10 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Meyer1228 | last post by:
VB6 - We have three data combo boxes with identical properties, each pointing to a different data file. We're using an odbc driver with a 4th gl indexed database. All that is working beautifully. ...
0
by: Andrew | last post by:
Hello, I am trying to create a chart whose underlying query is linked to 2 combo boxes on the same form. I want to pass the values from the combo boxes into the chart query to allow the chart...
1
by: ZZZ | last post by:
int dummy=Convert.ToInt32(das.Tables.Rows.ItemArray.ToString()); MessageBox.Show(dummy.ToString()); this.combo_opNaam.SelectedValue=dummy; ...
1
by: sonu | last post by:
I am working with a window application which will run on every computer on a network. but data will be only one machine on network. i am giving in connection string like.. connectionString =...
4
by: Elena | last post by:
Hi, I am filling in a combobox. I would like to concatenate two fields into the data combo box and display "last name, first name" I tried to displaymember = "employee_last_name" & ", " &...
0
by: UGURMURAT | last post by:
hi i managed to create adoc to link datagird so I see my external access database table inside the data gird. i managed to create a data combo box and list the names of the external document ...
0
by: sunilkds | last post by:
I want to main difference simple Combo box & DataCombo Box @ VB6.0 What is combox.listindex in DataCombo
1
by: sunilkds | last post by:
How to count total number of items in the Data Combo in Vb6.0
1
by: sunilkds | last post by:
I want code for how to clear values in the datacombo at run time. Plz give corect method or solution
4
by: sunilkds | last post by:
I want code for how to clear values in the datacombo box (not combo box) at run time. Plz give corect method or solution
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.