如何连接到SQL Server? [英] how connectivity to sql server?

查看:138
本文介绍了如何连接到SQL Server?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用DataAdapeter,DataSet,DataCommand进行连接?
请问SqlCommand和SqlDataAdapater之间的区别?

how to connection using DataAdapeter, DataSet, DataCommand?
wats the differnce between SqlCommand, SqlDataAdapater?

推荐答案

DataAdapter 是一个对象,充当数据库和应用程序之间的媒介.它从数据库中获取数据并填充应用程序对象(DataSet),反之亦然.

SqlCommand 对象定义每个sql命令,例如插入,更新,选择,删除等.我们将这些命令输入到DataAdapter 中,以确保适配器在需要时正确调用了适当的方法.

DataAdapter is an object that acts as a medium between the database and the application. It fetches data from the Database and fill application object (DataSet) and vice versa.

SqlCommand objects define each sql command, such as Insert, Update, Select, Delete etc. We feed in these commands to DataAdapter to ensure that the adapter called appropriate methods properly when required.

using(SqlConnection connection = new SqlConnection(constring))
{
  connection.open();
  SqlDataAdapter adpt = new SqlDataAdapter();
  using(SqlCommand cmd = new SqlCommand("select * from xyz", connection))
  {
    adpt.SelectCommand = cmd;
    adpt.Fill(ds, "xyz");
  }

}



因此DataSet ds将被值填充.
这实际上是关于数据库连接性的非常基础的知识.请参阅任何书籍以清除这些概念. :rose:



so DataSet ds will be filled up with values.
This is actually very basic knowledge on database connectivity. Please refer to any book to clear these concept. :rose:


这篇关于如何连接到SQL Server?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆