刚开始学数据库连接。。。一步一步来。。。
using (SqlConnection conn = new SqlConnection("Data Source = .; Initial Catalog = 数据库名; User Id = sa; Password = 123456;")) //连接数据库 { conn.open(); //打开数据库 using(SqlCommand cmd = conn.CreateCommand()) //创建数据库命令对象 { cmd.CommandText = "select * from MyLove"; using(SqlDataReader reader = cmd.ExecuteReader()) { while(reader.Read()) { string name = reader.GetString(1); MessageBox.Show(name); } } } }