C# 連結SQL Server,並讀出內容
SqlConnection myConnection = new SqlConnection("Data Source=;Initial Catalog=資料庫名稱;Persist Security Info=True;User ID=帳號;Password=密碼");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["Pwd"].ToString() + "\n";
label3.Text = label3.Text + myReader["Name"].ToString() + "\n";
}
myConnection.Close();
頁:
[1]