Click here to Skip to main content
15,891,704 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
The multi-part identifier "System.Data.DataRowView" could not be bound.
I am getting this error in this plz help me to how to rectify it in the below code
C#
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.SqlClient;
namespace DiscntdRtrvng
{
    public partial class DiscntdRtrvng : Form
    {
        SqlConnection con = new SqlConnection("server=.;user id=sa;password=123;database=Seed_Employee");
        SqlCommand cmd;
        DataSet ds;
        SqlDataAdapter da;
        string s;
        public DiscntdRtrvng()
        {
            InitializeComponent();
        }

        private void DiscntdRtrvng_Load(object sender, EventArgs e)
        {
            s = "select EmpId from Employee";
            da = new SqlDataAdapter(s, con);

            ds = new DataSet();
            da.Fill(ds, "emp");
           // DataRow row = ds.Tables[0].Rows[0];

            cbxEid.DataSource = ds.Tables[0];
            cbxEid.DisplayMember = "EmpId";
           //dataGridView1.DataSource = ds.Tables[0];
            
        }

        private void cbxEid_SelectedIndexChanged(object sender, EventArgs e)
        {
            s = "select * from Employee where EmpId=" + cbxEid.SelectedItem.ToString();
            da = new SqlDataAdapter(s, con);
            ds = new DataSet();
            da.Fill(ds, "emp");
            dataGridView1.DataSource = ds.Tables[0];
        }
    }
}
Posted
v2

1 solution

You error is probably this:
cbxEid.SelectedItem.ToString();

Instead, try with cbxEid.SelectedItem.Text or cbxEid.SelectedItem.Value
 
Share this answer
 
Comments
Yogesh_Mishra 22-Jan-13 13:56pm    
code don't work.
sjelen 23-Jan-13 5:48am    
This is absolutely correct way to get selected value from DropDown control.
If it doesn't work for you, you have a problem elsewhere or you're doing it wrong.

Down-voting an answer without explanation is rude.
Yogesh_Mishra 23-Jan-13 10:18am    
sorry, but for my code shown below,

ds = obj.SelectRecord("select * from library where bookid = " + combobid.SelectedItem.Text);

im getting error as :

Error 1 'object' does not contain a definition for 'Text' and no extension method 'Text' accepting a first argument of type 'object' could be found (are you missing a using directive or an assembly reference?)

if you have solution for this please comment,
THANKS......
sjelen 23-Jan-13 10:50am    
Is this error exactly on this line of code? What type of object is 'combobid'?
What kind of application are you making: web-forms, MVC, win-forms, WPF, SilverLight?

I can't help you without more info.

I guess you're making desktop application. My original solution is for web application.
You should use 'combobid.SelectedText' or 'combobid.SelectedValue.ToString()',
depending on how you bind data to combo box.
siddharth629 15-Jan-14 3:47am    
use this 'cbxEid.SelectedItem.ToString()'; or '"cbxEid.SelectedItem.ToString()"' it may be help u

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900