Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#4.0
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
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 30-Jul-12 3:22am
v2

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

You error is probably this:
cbxEid.SelectedItem.ToString();
 
Instead, try with cbxEid.SelectedItem.Text or cbxEid.SelectedItem.Value
  Permalink  
Comments
Yogesh_Mishra at 22-Jan-13 13:56pm
   
code don't work.
sjelen at 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 at 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 at 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 at 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)



Advertise | Privacy | Mobile
Web03 | 2.8.140709.1 | Last Updated 30 Jul 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid