code使用企业库将数据插入到SQL Server数据库 [英] Code for inserting data into SQL Server database using Enterprise library

查看:135
本文介绍了code使用企业库将数据插入到SQL Server数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新来的C#Windows应用程序的编码和使用企业库。

I am new to C# Windows Application coding and using Enterprise library.

我想用企业库4.1将记录插入到SQL Server 2008数据库

I want to insert records into SQL Server 2008 database using Enterprise Library 4.1

我收到的SqlCommand和之间的DBCommand混淆使用哪一个,何时使用。

I am getting confused between SQLCommand and DBCommand which one to use and when to use.

推荐答案

您不需要使用EntLib,只需使用老好ADO.NET:

You don't need to use EntLib, just use old good ADO.NET:

using (SqlConnection connection = new SqlConnection(connectionString))
using (SqlCommand command = connection.CreateCommand())
{
    command.CommandText = "INSERT INTO table (column) VALUES (@param)";

    command.Parameters.AddWithValue("@param", value);

    connection.Open();
    command.ExecuteNonQuery();
}


下面是对 MSDN :

public sealed class SqlCommand : DbCommand, ICloneable

从的DbCommand的SqlCommand派生

SqlCommand derives from DbCommand

这篇关于code使用企业库将数据插入到SQL Server数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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