SqlConnection thisConnection = new SqlConnection(
"Server=(local);Integrated Security=True;" +
"Database=stu");
thisConnection.Open();
SqlCommand thisCommand = thisConnection.CreateCommand();
SqlConnection thisConnection = new SqlConnection("Server=(local);Integrated Security=True;" +"Database=stu");//获得一个Connection连接实例
thisConnection.Open();//用连接实例打开数据库连接
SqlCommand thisCommand = thisConnection.CreateCommand();//通过连接实例创建Command对象,该对象包含书库操作方法
//初始化数据库连接,传入连接词
SqlConnection thisConnection = new SqlConnection(
"Server=(local);Integrated Security=True;" +
"Database=stu");
//打开连接
thisConnection.Open();
//初始化SqlCommand用于执行SQL语句
SqlCommand thisCommand = thisConnection.CreateCommand();
建立SQL连接,并将SQL 命令绑定到该链接。
接下来就可以给 命令赋值SQL 语句,来执行返回记录结果了。