找回密碼
 註冊
搜索
查看: 6135|回復: 0

C# 連結SQL Server,並讀出內容

[複製鏈接]
發表於 2007-4-13 16:36:10 | 顯示全部樓層 |閱讀模式
SqlConnection myConnection = new SqlConnection("Data Source=[IP];Initial Catalog=資料庫名稱ersist Security Info=True;User ID=帳號assword=密[EMAIL="c@m"]碼[/EMAIL]");
            myConnection.Open();
            SqlDataReader myReader = null;
            SqlCommand myCommand = new SqlCommand("select * from UserInfo where Account='" + textBox1.Text + "' OR Name like '%" + textBox1.Text + "%'", myConnection);
            myReader = myCommand.ExecuteReader();
            label1.Text = "";
            label2.Text = "";
            label3.Text = "";
            while (myReader.Read())
            {
                label1.Text = label1.Text + myReader["Account"].ToString() + "\n";
                label2.Text = label2.Text + myReader["wd"].ToString() + "\n";
                label3.Text = label3.Text + myReader["Name"].ToString() + "\n";
            }
            myConnection.Close();
您需要登錄後才可以回帖 登錄 | 註冊

本版積分規則

Archiver|手機版|彩色筆小沛的知識庫

GMT+8, 2024-5-3 03:02 , Processed in 0.017009 second(s), 10 queries , Gzip On, MemCache On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回復 返回頂部 返回列表