DBcommand 、DBconnection对象的使用示例。
来源:互联网 发布:女生做seo 编辑:程序博客网 时间:2024/06/07 06:53
// Takes a DbConnection and creates a DbCommand to retrieve data
// from the Categories table by executing a DbDataReader.
static void DbCommandSelect(DbConnection connection)
{
string queryString =
"SELECT CategoryID, CategoryName FROM Categories";
// Check for valid DbConnection.
if (connection != null)
{
using (connection)
{
try
{
// Create the command.
DbCommand command = connection.CreateCommand();
command.CommandText = queryString;
command.CommandType = CommandType.Text;
// Open the connection.
connection.Open();
// Retrieve the data.
DbDataReader reader = command.ExecuteReader();
while (reader.Read())
{
Console.WriteLine("{0}. {1}", reader[0], reader[1]);
}
}
catch (Exception ex)
{
Console.WriteLine("Exception.Message: {0}", ex.Message);
}
}
}
else
{
Console.WriteLine("Failed: DbConnection is null.");
}
}
// from the Categories table by executing a DbDataReader.
static void DbCommandSelect(DbConnection connection)
{
string queryString =
"SELECT CategoryID, CategoryName FROM Categories";
// Check for valid DbConnection.
if (connection != null)
{
using (connection)
{
try
{
// Create the command.
DbCommand command = connection.CreateCommand();
command.CommandText = queryString;
command.CommandType = CommandType.Text;
// Open the connection.
connection.Open();
// Retrieve the data.
DbDataReader reader = command.ExecuteReader();
while (reader.Read())
{
Console.WriteLine("{0}. {1}", reader[0], reader[1]);
}
}
catch (Exception ex)
{
Console.WriteLine("Exception.Message: {0}", ex.Message);
}
}
}
else
{
Console.WriteLine("Failed: DbConnection is null.");
}
}
0 0
- DBcommand 、DBconnection对象的使用示例。
- DBConnection的使用
- EF的连接对象 conventer DbConnection to SqlConnection
- DBConnection公共类的使用-------java操作数据库(3)
- DBConnection
- 无法将类型为“Finisar.SQLite.SQLiteConnection”的对象强制转换为类型“System.Data.Common.DbConnection”。
- DbConnection.java实现简单的MySQL数据库连接
- 多线程中互斥对象的使用示例
- java 对象流的使用示例-- ObjectOutputStream
- (三)关于SQL脚本在DbCommand里的执行
- DbCommand 参数
- 引用对象的使用和易产生bug的示例
- 【Java数据库连接类】封装数据库操作的连接类DBConnection
- 使用XMLHttprequest对象进行异步调用html页面的示例
- 看点:response对象,setContentType(String type)方法的使用示例。
- 类、方法、对象的定义与使用示例
- 例1.1 演示使用结构对象的示例程序。
- 使用外键对象示例
- CentOS7安装GitLab的步骤
- Maven 手动添加 JAR 包到本地仓库
- Linux 下编译安装软件,找不到共享库 xx.so 的解决办法
- Android ViewPager切换之PageTransformer接口中transformPage方法position参数使用详解
- 头文件相互包含引起的编译问题
- DBcommand 、DBconnection对象的使用示例。
- Redhat安装教程
- hdu3388(二分+容斥)。。无限超时
- HDU2044 一只小蜜蜂...
- PL/SQL连接oracle时弹出空白框
- Swift开发基础 二
- 看看Spring的源码——Bean加载过程
- Cocos2d-x 3.x项目设置Android里的横竖屏显示
- 关于The serializable class UsersServlet does not declare a static final serialVersionUID field of type