正文

[asp.net]ADO.NET笔记2006-09-15 18:06:00

【评论】 【打印】 【字体: 】 本文链接:http://blog.pfan.cn/bakers/18554.html

分享到:

ADO.NET   一.   关键字: 对象:Connection,  Command,  DataReader, DataAdapter 数据库: SQL, 聚合函数, 分组查询, 交叉查询. 数据控件: Repeater, DataList,  DataGrid 二. ADO.NET的结构. . 核心对象 1.       Connection : 建立与特定数据源的连接. 2.       Command : 对数据源执行命令. 3.       Datareader: 从数据源中读取只进且只读的数据流. 4.       DataAdaper :用于将数据填充倒DataSet. 注:SQL Server .NET 数据提供程序.   SqlConnection, SqlCommand, SqlDataReader, SqlDataAdapter.  以上四个对象都包含在System.Data.SqlClient命名控件中,   同理,OLE DB .NET的四个核心对象包含在 System.Data.OleDb命名控件中.   ODBC .NET略. 核心组件.  DataSet: 内部用XML描述数据, 具有与平台无关性.         常用对象: 1. DataTable和DataRow等.         DataAdapter被命名为:”数据适配器”. SQL语句分类.(略) SQL语句. (略) 聚合函数. (略) 交叉查询 以下实例很容易看懂  Select b.name from table1 a, table2 b, table3 c where a.course=c.course and a.strudent=b.struden and c.name=”baker” 总结: 交叉查询能够将数据表实例化, 以后可能有大 用处. 三.对象的使用.   1. Connection : 如下定义:  SqlConnection conn=new SqlConnection(); 构造函数如下: Name Description SqlConnection () Initializes a new instance of the SqlConnection class. Supported by the .NET Compact Framework. SqlConnection (String) Initializes a new instance of the SqlConnection class when given a string that contains the connection string. Supported by the .NET Compact Framework 第二个构造函数 string 为connectstring .   Name Description ConnectionString Overridden. Gets or sets the string used to open a SQL Server database. ConnectionTimeout Overridden. Gets the time to wait while trying to establish a connection before terminating the attempt and generating an error. Container  Gets the IContainer that contains the Component.(Inherited from Component.) Database Overridden. Gets the name of the current database or the database to be used after a connection is opened. DataSource Overridden. Gets the name of the instance of SQL Server to which to connect. FireInfoMessageEventOnUserErrors Gets or sets the FireInfoMessageEventOnUserErrors property. PacketSize Gets the size (in bytes) of network packets used to communicate with an instance of SQL Server. ServerVersion Overridden. Gets a string that contains the version of the instance of SQL Server to which the client is connected. Site  Gets or sets the ISite of the Component.(Inherited from Component.) State Overridden. Indicates the state of the SqlConnection. StatisticsEnabled When set to true, enables statistics gathering for the current connection. WorkstationId Gets a string that identifies the database client.     实例: 连接SQL数据库 SqlConnection conn; conn=new SqlConnection(“server=localhost;database=index;uid=baker;pwd=baker”); Conn.open(); 2. Command   定义方式和Connection对象一样.   构造函数: Name Description SqlCommand () Initializes a new instance of the SqlCommand class. Supported by the .NET Compact Framework. SqlCommand (String) Initializes a new instance of the SqlCommand class with the text of the query. Supported by the .NET Compact Framework. SqlCommand (String, SqlConnection) Initializes a new instance of the SqlCommand class with the text of the query and a SqlConnection. Supported by the .NET Compact Framework. SqlCommand (String, SqlConnection, SqlTransaction) Initializes a new instance of the SqlCommand class with the text of the query, a SqlConnection, and the SqlTransaction. Supported by the .NET Compact Framework. Properties       CommandText Overridden. Gets or sets the Transact-SQL statement or stored procedure to execute at the data source. CommandTimeout Overridden. Gets or sets the wait time before terminating the attempt to execute a command and generating an error. CommandType Overridden. Gets or sets a value indicating how the CommandText property is to be interpreted. Connection Gets or sets the SqlConnection used by this instance of the SqlCommand. Container  Gets the IContainer that contains the Component.(Inherited from Component.) DesignTimeVisible Overridden. Gets or sets a value indicating whether the command object should be visible in a Windows Form Designer control. Notification Gets or sets a value that specifies the SqlNotificationRequest object bound to this command. NotificationAutoEnlist Gets or sets a value indicating whether the application should automatically receive query notifications from a common SqlDependency object. Parameters Gets the SqlParameterCollection. Site  Gets or sets the ISite of the Component.(Inherited from Component.) Transaction Gets or sets the SqlTransaction within which the SqlCommand executes. UpdatedRowSource Overridden. Gets or sets how command results are applied to the DataRow when used by the Update method of the DbDataAdapter.

阅读(4974) | 评论(0)


版权声明:编程爱好者网站为此博客服务提供商,如本文牵涉到版权问题,编程爱好者网站不承担相关责任,如有版权问题请直接与本文作者联系解决。谢谢!

评论

暂无评论
您需要登录后才能评论,请 登录 或者 注册