使用Ado.net Windows应用程序从Sql Server检索数据 [英] retrieve data from Sql server using Ado.net windows application

查看:67
本文介绍了使用Ado.net Windows应用程序从Sql Server检索数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要知道如何从数据库(Sql)中检索特定数据并将其放在文本框中,这是最好的方法! ,

i need to know how i can retrieve the specific data from database (Sql)and put it in text boxes , which is the best way ! ,

推荐答案

尝试:
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;
                }
            }
        }
    }


这篇关于使用Ado.net Windows应用程序从Sql Server检索数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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