C# Fill combo box from SQL DataTable

后端 未结 3 1035
梦谈多话
梦谈多话 2020-12-21 20:56
DataTable _dt = new DataTable();

using (SqlConnection _cs = new SqlConnection(\"Data Source=COMNAME; Initial Catalog=DATABASE; Integrated Security=True\"))
{
    st         


        
3条回答
  •  旧巷少年郎
    2020-12-21 21:16

    I think the problem is that you are trying to insert multiple columns into a comboBox (which can accept only one column). Adjust your SELECT statement so that it combines all of the data you need into one column:

    Example: ´SELECT Name + ' ' LastName + ' '+ ID AS 'DoctorData' FROM Doctor´

    By using the + operator you can combine multiple columns from the database, and represent it as a single piece of data. I think that your code should work after that (you can even comment the foreach loop, I think that adding data source to your comboBox will be enough)

提交回复
热议问题