Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/308.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 将数据库中的值添加到组合框_C#_Sql_Database_Ssms - Fatal编程技术网

C# 将数据库中的值添加到组合框

C# 将数据库中的值添加到组合框,c#,sql,database,ssms,C#,Sql,Database,Ssms,因此,我已经从表单连接了我的数据库,我想知道如何将Strand_名称和Status_名称的数据添加到它们所属的相应组合框中。我把Add.Items的事情搞砸了,我不知道我要用哪种代码,我应该把代码放在什么地方。有什么建议吗 可以使用数据绑定将表映射到CBO。用户将看到名称,您的代码可以使用DisplayMember和ValueMember获取ID。这里有数百篇文章展示了如何创建WinForms或WPF应用程序?这是你的作业吗?这是WPF应用程序。不,这是学校的注册数据库。 //Try M

因此,我已经从表单连接了我的数据库,我想知道如何将Strand_名称和Status_名称的数据添加到它们所属的相应组合框中。我把Add.Items的事情搞砸了,我不知道我要用哪种代码,我应该把代码放在什么地方。有什么建议吗


可以使用数据绑定将表映射到CBO。用户将看到名称,您的代码可以使用DisplayMember和ValueMember获取ID。这里有数百篇文章展示了如何创建WinForms或WPF应用程序?这是你的作业吗?这是WPF应用程序。不,这是学校的注册数据库。
    //Try My code.
    // Call it On form load or IntializeComponent()

    private void GetStrand()
      {//depending on your database bind data like..
         string query="select strand_id,strand_name from strand ";
         using(MysqlConnection con =new MysqlConnection(//your connection string here)
         {
           con.open();
           using(MysqlCommand cmd = new MysqlCommand(query,con)
          {
          MysqlDataReader reader =cmd.ExecuteReader();
          while(reader.read())
          {
           string _strand= reader.GetString("strand_name");
           cbostrand.Items.Add(_strand);

           }
           }
          }

       }