c#读取SqlServer数据显示到textbox中

来源:互联网 发布:伪娘神奇宝贝 知乎 编辑:程序博客网 时间:2024/05/17 12:19
        private void button1_Click(object sender, EventArgs e)
        {
            SqlConnection sqlConn = new SqlConnection();
            sqlConn.ConnectionString = "server = WIN-0UEOCR8V967\\SQL2005; uid = sa; pwd =1212123; database = db1;";//设置连接字符串
            sqlConn.Open();


            SqlCommand myCommand = sqlConn.CreateCommand();
            //int mycount=0;
            myCommand.CommandText = "select name,password from management";


            SqlDataReader myReader = myCommand.ExecuteReader();
            myReader.Read();
        


            while (myReader.Read())
            {


                textBox2.Text = Convert.ToString(myReader["name"]);
                textBox3.Text = Convert.ToString(myReader["password"]);
                Thread.Sleep(3000);




             }
            myReader.Close();
            sqlConn.Close();
        }
原创粉丝点击