private static string strConnect = System.Configuration.ConfigurationManager.AppSettings["connStr"];
然后在该页面的Page_Load方法里添加以下代码:
// 数据库连接
OleDbConnection objConnection = new OleDbConnection(strConnect);
// 数据库命令
OleDbCommand objCommand = new OleDbCommand("", objConnection);
try
{
// 设置Sql语句
objCommand.CommandText = "SELECT SID,SName,Sex FROM StudentInfo ORDER BY SID";
// 打开数据库连接
if (objConnection.State == ConnectionState.Closed)
{
objConnection.Open();
}
文章来源于领测软件测试网 https://www.ltesting.net/