logo
down
shadow

Can't read the value member setting from the data reader to combobox


Can't read the value member setting from the data reader to combobox

By : RevvyBoy
Date : November 16 2020, 06:23 AM
Hope this helps I suggest the following approach:
First: you create some class for your data items:
code :
class MyDataItem 
{
    public string PartyID { get;set; }
    public string PartyName { get;set; }
}
public void getPartyNamesCombo()
{
    SqlDataReader reader = new VotingOP().getPartyNamesToCombo();
    while (reader.Read())
    {
        cmbPartyName.Items.Add(new MyDataItem() { 
            PartyID = reader["partyID"].ToString(), 
            PartyName = reader["partyName"].ToString() 
        });
    }
    cmbPartyName.ValueMember = "PartyID";
    cmbPartyName.DisplayMember = "PartyName";
}
MyDataItem selectedItem = cmbPartyName.SelectedItem as MyDataItem;
if (selectedItem != null) 
{
    MessageBox.Show(String.Format("You've just selected the '{0}' party with the ID {1}",  selectedItem.PartyName, selectedItem.PartyID));
}


Share : facebook icon twitter icon
Setting DataRow as ComboBox's value member

Setting DataRow as ComboBox's value member


By : Ali Haider Syed
Date : March 29 2020, 07:55 AM
To fix this issue First of all thank you Adam Robinson, I'm sure your answer was correct, but it just wasn't what I wanted to hear. I solved my problem in a different way and I think it may be useful to someone else, so I am posting it here.
What I did was I created a new class, in my case I named it ListObject, which had a property DataRow (as you will see later it works for other types too, I just used this since this is what I actually wanted as my Item value property). It also overrides methods:
code :
public class ListObject
{
    public DataRow element;

    public String DisplayObject = null;

    public ListObject(DataRow dr)
    {
        element = dr;
    }

    public ListObject(DataRow dr, String dspObject)
    {
        element = dr;
        DisplayObject = dspObject;
    }

    public override String ToString()
    {
        if (DisplayObject == null) throw new Exception("DisplayObject property was not set.");

        return element[DisplayObject].ToString();
    }

    public override bool Equals(object obj)
    {
        if (obj.GetType() == typeof(ListObject))
            return Equals(((ListObject)obj).element, this.element);
        else return base.Equals(obj);
    }

    public override int GetHashCode()
    {
        return base.GetHashCode();
    }
}
dtUsers.ReadXml(Program.Settings.xmlInputUsers);

foreach(DataRow dr in dtUsers.Rows) 
{
    cmbUser.Items.Add(new ListObject(dr, "Name"));
}
cmbUser.SelectedItem = new ListObject(dlg.SelectedDataRow);
Kendo : ComboBox in a grid - Sending additional data of selected combobox to combobox Read()

Kendo : ComboBox in a grid - Sending additional data of selected combobox to combobox Read()


By : Primoz
Date : March 29 2020, 07:55 AM
I think the issue was by ths following , Here's the Combo Box defined in a partial view in ~/Views/Shared/EditorTemplates/ComboBoxTemplate
code :
@(Html.Kendo().ComboBox()
          .Name("AcctName")//must match Field Name that is being edited
          .HtmlAttributes(new { style = "width:250px" })
          .DataTextField("AcctName")
          .DataValueField("AcctCd")
          .Filter(FilterType.StartsWith)
          .AutoBind(true)
          .MinLength(3)
          .DataSource(source =>
          {
              source.Read(read =>
              {
                  read.Action("GetCombo", "GridPost").Data("OnAdditionalData");
              })
              .ServerFiltering(true);
          })          
)
columns.Bound(x => x.AcctName).Title("Acct Name").EditorTemplateName("ComboBoxTemplate");

 function OnAdditionalData() {          

            var entityGrid = $("#ProposalGridX").data("kendoGrid");
            var selected = entityGrid.dataItem(entityGrid.select());
            //if the id is off the Grid Row and not the ComboBox
            //select the row and pull the fields
            //selected.PropertyName

            return {
                text : $("#AcctName").data("kendoComboBox").text(),
                 val : $("#AcctName").data("kendoComboBox").value()
            };
        }

   public JsonResult GetCombo(string text, string val)
   {
         List<PortfolioViewModel> model = new AUMBusiness().GetAum(DateTime.Now);

           if (!string.IsNullOrEmpty(text))
            {
               model = model.Where(x => x.AcctName.StartsWith(text)).ToList();
            }

         return Json(model, JsonRequestBehavior.AllowGet);
    }
Data from SQL reader to datatable - Invalid attempt to call Read when reader is closed

Data from SQL reader to datatable - Invalid attempt to call Read when reader is closed


By : Daniel S. Orgler
Date : March 29 2020, 07:55 AM
will help you I am keep trying and still don't know how to fix this, keep getting same error. I want to get data from the database to txt file. , Try insted your code, something like this:
code :
 DataTable myDataTable = new DataTable();


        using (SqlConnection myConnection = new SqlConnection(yourDBconn)
        {
                yourDBconn.Open();
                using (SqlDataAdapter myAdapter = new SqlDataAdapter(strYourQuery, yourDBconn))
                {
                    myAdapter.Fill(myDataTable);
                }
            }
        }
C# MVC EF error - data reader incompatible member of the type does not have a corresponding column in the data reader wi

C# MVC EF error - data reader incompatible member of the type does not have a corresponding column in the data reader wi


By : JordanS
Date : March 29 2020, 07:55 AM
Hope that helps I'm trying to create a stored proc for the first time, but I just can't get it right. So I have a proc which is returning a count from the db, based on the parameters being fed to it. I'm not sure what I'm doing wrong, if the SQL is wrong or if I'm mapping the function incorrectly. Here's my SQL: , You probably need to give the count value a name, like this:
code :
SELECT COUNT(*) AS RESULT_OF_COUNT
from ...
Data reader is incompatible... member does not have corresponding column in data reader

Data reader is incompatible... member does not have corresponding column in data reader


By : Mathieu Filotto
Date : March 29 2020, 07:55 AM
it helps some times Rather than updating the view, you can also update the Function Import:
Go to the Model Browser window Expand the EntityContainer Open the Function Import in the Mapping Details window If the entity name (left column) does not match the expected field name (right column), you can change the right-hand column to match what the returned field is actually called.
Related Posts Related Posts :
  • Why does C# also not allow empty conditions in while loops?
  • Unable to get a block of code into my regex match groups
  • What is difference between dbcontext.Add and dbcontext.AddObject
  • How do I update the file version number of C# DLL without recompiling?
  • Value for html control always null
  • HttpClient hangs when timeout is setting (Windows Phone)
  • Handle Multiple Form tag in asp.net page?
  • create word document with html content in c#
  • Confusion about Find And Replace
  • Format sms messages in Clickatell
  • Automated Function Overload
  • String to date in MS Access SQL statement gives type mismatch error
  • ShowDialog exiting on certain events
  • Is there a try Convert.ToInt32... avoiding exceptions
  • How to move wpf application into minimize tray at Window Start-up C#?
  • How to change display format of long variable?
  • How to use Addfields in MongoDB C# Aggregation Pipeline
  • MsTest TestCleanup method not called when an unhandled exception is thrown
  • missing last data when exporting gridview to excel
  • How to add array of objects to List in c#
  • Lambda Expression to order (sort) my list collection
  • Library for displaying music notation
  • How to compare two dictionaries in c# and get the output as True and False after validation
  • specify fields to be serialized with JSON
  • How do you obtain the content of a specific node using XmlDocument in C#?
  • How to ignore the first line in a csv file when you read the csv file in C#
  • c# - Problem calling public void from class
  • How to tell a class which objects it should create? Type vs. object confusion :(
  • Save CheckBox state to xml
  • WIX CAQuietExec NETSH Command Fails
  • Issues sending http put request every 60 seconds to RoR app
  • ConfigurationManager.ConnectionStrings.ConnectionString Issue
  • Real size WPF controls for printing
  • How to cancel properly?
  • C# String multiplication error
  • Using Solrnet and Assigning Attributes with Entity Framework Generated POCOs
  • Regex pattern for single backslash
  • TextBox: insert spaces for credit card number?
  • C# DLL loaded for exe-application is not found when launching similar DLL by rundll32.exe
  • Debug a Windows Service with WCF library
  • Open a file from an external assembly?
  • Servicestack RegistrationFeature Unable to bind request
  • Index was outside the bounds of the array confusion
  • Error in Xml to List code. The ':' character, hexadecimal value 0x3A, cannot be included in a name
  • I am trying to do a while loop with a string conditional statement in C#
  • C# 'Cannot access a disposed object. Object name: 'SslStream'.'
  • How to make Gecko use seperate CookieContainer per instance?
  • C# Advanced form "please wait"
  • Send and Receive data C# using network stream
  • How to discover that appsettings changed in C#?
  • Check what needs full trust
  • What is the execution order of an MVC Razor view/layout
  • Table designer (Entity Framework) is too resource intense
  • How to clean up an exception string so it can be displayed via Javascript Alert?
  • Configuring Amazon SES Feedback Notifications via Amazon SNS in ASP.NET MVC (C#)
  • C# api responce and request
  • Dynamodb putitem function not working properly
  • theme in windows phone(light or dark) using c#
  • Backup attached database file(.mdf) using c# and SQL Server
  • What is 'TextFile' and where it is uses in WPF project
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org