Errors with codes for deleting using linq

后端 未结 4 1362
生来不讨喜
生来不讨喜 2021-01-27 07:43

I encounter a problem regarding the deleting of data using combo box. The error prompted me I have no idea of how to solve it. Anyone can help me about it?

priva         


        
相关标签:
4条回答
  • 2021-01-27 08:09

    I think you put your code in wrong place.. you just add items on same combo select change (cbLocationData_SelectedIndexChanged) that's wrong
    put your code other appropriate place in which adding items are not part of same events

    0 讨论(0)
  • 2021-01-27 08:23

    Your event is firing on SelectedindexChanged of the cb you're trying to fill. Try putting it in the page load or a more appropriate place?

    0 讨论(0)
  • 2021-01-27 08:29

    Create a method something like this:

    private void LoadLocation()
    {
           using (testEntities Setupctx = new testEntities())
            {
                var storeLocation = (from vL in Setupctx.locations
                                     select new
                                             {
                                               Location1  =vL.Location1
                                             }
                                     );
    
                    cbLocationData.DataTextField = "Location1";
                    cbLocationData.DataSource = storeLocation;
                    cbLocationData.DataBind();
    
            }
    }
    

    Then on your page load(asp.net)/form Load(winform) add:

               LoadLocation();
    

    Hope this help.

    Regards

    0 讨论(0)
  • 2021-01-27 08:33
    private void cbLocationData_SelectedIndexChanged(object sender, EventArgs e)
    {
        using (testEntities Setupctx = new testEntities())
        {
            var storeLocation = (from vL in Setupctx.locations
                                 where vL.Location1 == vL.Location1
                                 select vL.Location1);
    
            foreach (var locationData in storeLocation)
            {
                cbLocationData.Items.Add(locationData.ToString());
            }
        }
    }
    

    Is it possible that locationData needs set to tostring() or convert(), depending on the data type? Everything looks like it should be working correctly.

    0 讨论(0)
提交回复
热议问题