如何从数据库中获取数据并使用C#Window Application Form将其插入到我的组合框中? [英] How to get data from the database and insert it into my combo box using C# Window Application Form?

查看:81
本文介绍了如何从数据库中获取数据并使用C#Window Application Form将其插入到我的组合框中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好。



我想知道如何从我的表(tblClass)获取数据(GradeLevel)并将其放入我的组合框中使用C#。我是这种语言的新手。希望有人能帮助我:)提前谢谢:)

Hello everyone there.

I would like to know on how to get the data(GradeLevel) from my table (tblClass) and put it inside my combo box using C#. I am new about this language. Hoping anyone can help me :) Thanks in advance :)

推荐答案

简单来说就像是:

In simple it could be like:
using (SqlConnection sqlConnection = new SqlConnection("connstring"))
{
    SqlCommand sqlCmd = new SqlCommand("SELECT * FROM tblClass", sqlConnection);
    sqlConnection.Open();
    SqlDataReader sqlReader = sqlCmd.ExecuteReader();

    while (sqlReader.Read())
    {
        cbDoctor.Items.Add(sqlReader["name"].ToString());
    }

    sqlReader.Close();
}



记住这是一种格式,而不是整个代码。另见:

填写c#中的组合框 [ ^ ]


这篇关于如何从数据库中获取数据并使用C#Window Application Form将其插入到我的组合框中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆