Hi,
System.Data.DataRowView in combobox
That happens to me when I have misspelled the column name being assigned to
the DisplayMember property. I've found that both the spelling and the case
must match the column name.
Hi,
System.Data.DataRowView in combobox
That happens to me when I have misspelled the column name being assigned to
the DisplayMember property. I've found that both the spelling and the case
must match the column name.
This is a symptom of the FieldName supplied in
Me.cboProductName.DisplayMember = "ProductName"
being incorrect. If this does not exactly match to a valid fieldname (Case
Sensitive) exposed by the collection you will get:-
"System.Data.DataRowView"
If what you want is the value from the column of the selected row, an easier
way might be to set :
cboSelectResource.ValueMember = "ResourceDetails";
then when you want to retrieve it:
string wholeRecord = cboSelectResource.SelectedValue
However, for this to work, you'll have to get the first problem resolved.
On the first problem, have you tried setting the DataSource to
dsResourceGroup.TableName instead of instead of dsResourceGroup.Tables[0]?
Substitute the actual name of the Table for TableName.
Can we assume that the column ResourceDetails is defined as a string and
that the Dataset dsResourceGroup has only the one Table in it?
Let me know if this works,
I ran into the exact same issue. I ended up wrapping a Try/Catch handler
around the code and explictly catch the cast error and ignore it. Something
like this:
try
{
int myId = (int)myCombo.SelectedValue;
// more code here
}
catch (InvalidCastException)
{
// do nothing
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
Hi I get a different error.. I am using VB.net and creating a Window Application and my platform is VS 2005
My scenario is this..
I have 2 combobox and a textbox
when i select value from 1st combobox, it fetches the associated record from the db and populates the 2nd combobox.
My requirement is when i select value from 2nd combobox it should fetch the associated record from the db and display in the textfield.
2nd combobox can have multiple values but textfield would show only 1.
now my prob
when i select value from 1st combo, i can clearly see the 2nd combo populated with values, i expect... but i run into trouble when i try to read the value from the 2nd combo and run the query against the db... this is where i see System.Data.DataRowView.
following is my code
********************************************
this is to Populate 2nd combo
********************************************
cmdText = "Select Location_Name From Location_Details Where Region_Name=" + "'" & strRegionName & "'" + " " + "AND" + " " + "Location_Category=" + "'" & strLocationType & "'" + " " + "AND" + " " + "Location_Business_Group=" + "'" & strBUType & "'"
Try
sqlcmd = New SqlCommand(cmdText, sqlConn)
sqlDA = New SqlDataAdapter
sqlDA.SelectCommand = sqlcmd
sqlConn.Open()
'Creating the dataset and reading data into it
sqlDS = New DataSet
sqlDA.Fill(sqlDS, "Location_Details")
sqlDT = sqlDS.Tables("Location_Details")
cmbx_LocationName.DataSource = sqlDT
cmbx_LocationName.DisplayMember = "Location_Name"
cmbx_LocationName.ValueMember = "Location_Name"
'intLocationName = cmbx_LocationName.Items.Count
Catch ex As Exception
MessageBox.Show(ex.Message)
sqlConn.Close()
Finally
sqlConn.Close()
End Try
*************************************
***************************************
this is to read the value when the 2nd combo is clicked to select value
***************************************
strLocationName_Selected = cmbx_LocationName.SelectedItem.ToString
cmdText = "Select Location_Circuit_ID From Location_Details Where Location_Name=" + "'" & strLocationName_Selected & "'"
when i do a Messagebox.show(cmdText) I get this
Select Location_Circuit_ID From Location_Details Where Location_Name= 'System.Data.DataRowView'
I verified the DisplayMember and ValueMember and found the Column Name consistent and correct in both the application code as well as the db
Please help....
Bookmarks