且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用Ado.net Windows应用程序从Sql Server检索数据

更新时间:2023-02-07 08:35:34

尝试:
using (SqlConnection con = new SqlConnection(strConnect))
    {
    con.Open();
    using (SqlCommand com = new SqlCommand("SELECT iD, description FROM myTable", con))
        {
        using (SqlDataReader reader = com.ExecuteReader())
            {
            while (reader.Read())
                {
                int id = (int) reader["iD"];
                string desc = (string) reader["description"];
                tbId.Text = id.ToString();
                tbDesc.Text = desc;
                }
            }
        }
    }