Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

unabele to retreieve combobox datamember value

Posted on 2009-05-15
2
Medium Priority
?
392 Views
Last Modified: 2012-05-07
Hi experts

I want to access data from two tables client_mst and client_notes

I have a combobox in which i want to set displaymember as  client_mst.client_name and DispalayValue as client_mst.client_id

depending on the combobox SelectedValue  i want to display the values in the datagrid view as


@"select client_notes.date,client_notes.message from client_notes where client_notes.client_id =" (int)clNamecomboBox.SelectedValue ;


Here i can't retreieve combobox selectedvalue  clNamecomboBox.SelectedValue is not showing any value

and i'm not sure whether to use two dataadapters for two sql statements

pls help me.
Thanks.
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 MySql.Data;
using MySql.Data.MySqlClient;
 
namespace Easypeasy_Office_Management
{
    public partial class easypeasyForm : Form
    {
        public easypeasyForm()
        {
            InitializeComponent();
            
        }
 
 
        private void btnNotes_Click(object sender, EventArgs e)
        {
            notesPanel.Enabled = true;
            notesPanel.Visible = true;
            string connString = @"server=localhost;database=abc;user id=root;password=kodanda;";
            string sql = @"select  client_name,client_no,notes_message as Notes,notes_date as `Date` from client_mst,client_notes  where client_mst.client_id=client_notes.client_id";
            MySqlConnection conn = null;
           
            try
            {
                conn = new MySqlConnection(connString);
                conn.Open();
               
                MySqlDataAdapter dAdapter = new MySqlDataAdapter(sql, conn);
                MySqlCommandBuilder cBuilder = new MySqlCommandBuilder(dAdapter);
                DataTable dTable = new DataTable();
                dAdapter.Fill(dTable);
                BindingSource bSource = new BindingSource();
                bSource.DataSource = dTable;
               
                MessageBox.Show("demonstrating");
                MessageBox.Show(conn.Database);
                clNamecomboBox.DataSource = bSource;
                clNamecomboBox.DisplayMember = "client_name";
                clNamecomboBox.ValueMember = "client_mst.client_id";
                clNotextBox.Text = (string)clNamecomboBox.SelectedValue;
                dataGridViewNotes.DataSource = bSource;
                dAdapter.Update(dTable);
                
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error" + ex);
            }
            finally
            {
             
                conn.Close();
            }
 
        }
 
       
        
        
        
    }
}

Open in new window

da.bmp
0
Comment
Question by:APPIREDDY
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 11

Expert Comment

by:Mihai Stancescu
ID: 24407054
Try to bind directly to the data table not to a binding Source....



Hope this helps!

Regards,
Mishu
0
 

Accepted Solution

by:
APPIREDDY earned 0 total points
ID: 24481644
I FOUND THE ANSWER
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question