APPIREDDY
asked on
unabele to retreieve combobox datamember value
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_n otes.messa ge from client_notes where client_notes.client_id =" (int)clNamecomboBox.Select edValue ;
Here i can't retreieve combobox selectedvalue clNamecomboBox.SelectedVal ue is not showing any value
and i'm not sure whether to use two dataadapters for two sql statements
pls help me.
Thanks.
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_n
Here i can't retreieve combobox selectedvalue clNamecomboBox.SelectedVal
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();
}
}
}
}
da.bmp
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Hope this helps!
Regards,
Mishu