ADO.NET 之sqlConnection 对象使用摘要
来源:互联网 发布:混血失败知乎 编辑:程序博客网 时间:2024/06/06 04:54
3.1 生成sqlConnection对象
string strConnection ='Data source=.;initial catalog=northwid';
sqlConnection cn = new sqlConnection(strConnection);
3.2打开sqlConnection对象
cn.Open();
3.3关闭sqlConnection对象
cn.Close();
3.4自行清除连接
使用using块,确保调用Close方法
using (sqlConnection cn = new sqlConnection(strConnection))
{
cn.Open()
}//执行到这个块时,会隐式调用Close();方法
3.5.2连接字符串生成器
SqlConnectionStringBuilder sb= new SqlConnectionStringBuilder();
sb['Datab Source']=@'./SQLExpress';
sb['Initital Catalog']='Northwind';
sb['Intergrated Security']=true;
//获取字串
string strConnection = sb.ConnectionString;
3.7.1创建sqlCommand
DBCommand cmd = cn.CreateCommand();
cmd.CommandText ='select 1 + 1';
cmd.ExecuteNonQuery();
cmd.CommandText ='Insert into ...';
cmd.ExecuteNonQuery();
3.7.2开始使用sqlTransaction
sqlConnection cn = new sqlConnection(strConnection);
cn.open();
sqlTransaction tn = cn.BeginTransaction();
3.7.3获取架构信息
DataTable tb = cn.GetSchema('Tables');
foreach(DataRow row in tb.rows)
Console.Write(row['TABLE_NAME']);
- ADO.NET 之sqlConnection 对象使用摘要
- 黑马程序员之ADO.NET学习笔记:SqlConnection(连接对象)
- ADO.NET学习之SqlConnection,SqlCommand
- ADO.NET的SQLConnection
- SqlTransaction、SqlConnection和SqlCommand对象实现ADO.NET事务处理
- ADO.NET 主要的三个对象(SqlConnection/SqlCommand/SqlDataReader)
- ADO.net的SqlConnection问题
- ADO.NET摘要1
- ADO.NET之sqlCommand对象
- ADO.NET之SqlDataAdpter对象
- ADO.NET对象之 DataTable
- ADO.NET对象之 DataTable
- ADO.NET对象的使用
- ADO.NET之5-使用Command对象删除记录---ShinePans
- ADO.NET链接和摘要
- ADO.NET使用之经验谈
- ADO.NET读书笔记系列之------Connection对象
- ADO.NET Quiz 之对象序列化
- 学习STL map, STL set之数据结构基础(转)
- flash 日历
- BlackBerry视频播放编程
- TOMCAT设置JDK
- SQL Server大小写区分方法总结
- ADO.NET 之sqlConnection 对象使用摘要
- AIR是什么?.air文件如何打开?flex如何运行air文件
- ADO.NET之sqlCommand对象
- java mail 通用类
- 命令行下的Python进度条
- Android蓝牙API之BluetoothAdapter类
- 2010-6-28 Ruby on Rails Webアプリケーションフレームワーク概要
- 正确使用UDP广播(C++代码)
- 当java clob数据长度在1000~2000