Home > Software design >  Problem combo box does not connect to database
Problem combo box does not connect to database

Time:12-15

I have a problem with merging data in combo box on the following code. I presented my solution, but it shows me an error "Unable to bind to new display member. Arg_ParamName_Name" at: CB.Trucker.ValueMember

            
            SqlConnection co = new SqlConnection("Data Source=\"localhost, 1433\";Initial Catalog=Transporting;User ID=******;Password=*******");
            co.Open();
            SqlCommand comd = new SqlCommand("SELECT CONCAT(EmpFirstName,' ',EmpLastName) as Trucker FROM Employees ", co);
            
            SqlDataReader readerv3;
            readerv3 = comd.ExecuteReader();
            DataTable data = new DataTable();

            data.Columns.Add("Trucker", typeof(string));
            data.Load(readerv3);
            CbTrucker.ValueMember = "Trucker";
            CbTrucker.DataSource = data;
            co.Close();

CbTruck{} field has defined values

 public string Ordtruck { get => CbTruck.Text; set => CbTruck.Text=value; }

I have no idea what's wrong. I'm using the same script to display a different problem I even wrote a procedure, that only displays these values, but it still doesn't work.Even when the select (comd) query is modified by data.Columns.Add, it still displays the same error

CodePudding user response:

there was a problem with calling the CBTruck class, which was called in an earlier event and conflicted with the current example, it was enough to remove the previously used class

  • Related