问题标签 [ado.net]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
2 回答
2830 浏览

.net - 如何将存储为 oracle blob 的图像存储到 Image 对象中

我正在尝试检索存储在 oracle blob 中的图像并将其放置在新的 System.Drawing.Image 实例中。我知道我可以将流写入磁盘上的 temp.bmp 文件并从那里读取它,但这对我来说还不够 l33t。如何将 blob 对象直接转换为图像?

0 投票
4 回答
37063 浏览

.net - C# 通过连接字符串检索正确的 DbConnection 对象

我有一个连接字符串被传递给一个函数,我需要基于这个字符串创建一个基于 DbConnection 的对象(即 SQLConnection、OracleConnection、OLEDbConnection 等)。

是否有任何内置功能可以做到这一点,或者有任何第三方库可以提供帮助。我们不一定要构建这个连接字符串,所以我们不能依赖写入字符串的格式来确定它的类型,我宁愿不必编写可能的连接字符串的所有组合和排列

0 投票
6 回答
16021 浏览

.net - .NET 迭代数据表中行的最快方法?

从 DataTable 读取/比较行信息时,哪个通常最快?

如果有区别,在什么情况下使用其中一种是值得的?

提前感谢您的任何指导!

0 投票
2 回答
3890 浏览

c# - 将 CheckBox 列添加到具有持久性的 GridView

我有一个 ASP.NET 应用程序,可以将各种视图显示到一个大型蛋白质序列数据库中。当访问者浏览数据时,我希望他们能够在 GridView 行中选择一个 CheckBox 来标记序列,以便以后下载为压缩文本文件。我不想存储选择,因此它们应该对会话有效。

我现在的想法是向 GridView 添加一个 TemplateField,然后向其中添加一个 CheckBox。我打算处理检查事件并将序列 ID 存储在会话状态中。当用户前往下载页面时,我将获取会话数据,显示他们将要下载的序列列表,然后将文件一起发送。显然,我还必须在每次表单加载/页面切换时重新解析会话数据。

所以我实际上对此有几个问题:

1)我做的工作太多了吗?有没有更简单的方法来实现这个?

2)会话状态的所有往返服务器是否可能是性能问题?我可以在页面上放置一个“保存下载”按钮来批量处理它以帮助解决问题。处理检查事件似乎更具容错性,因为如果您离开,您不会意外丢失您的状态。

3) 是否可以按复选框列对 GridView 进行排序?我想先按复选框列排序,然后是当前排序的列(例如,如果 GridView 按姓氏排序,则按复选框列排序,然后按姓氏排序)。

万一这很重要,我正在使用 C#、.NET 3.5、VS2008,并且我正在使用从 SQLServerExpress 表创建 GridView 的简单拖放方式。

0 投票
2 回答
136 浏览

sql - 从 SQLDataAdaptor.Update 检索新 ID

当对表执行 SQLDataAdapater.Update 时,您将如何检索每一行的 @@IDENTITY 值?

例如。是否可以修改/拦截由 SQLCommandBuilder 生成的 InsertCommand,例如添加一个输出参数,然后在 da.RowUpdated 事件中检索其值???

0 投票
2 回答
232 浏览

.net - 是否有任何类(或方法)可以创建格式化的连接字符串,给定提供者名称和用户 ID、密码等?

例如。

我会编写自己的类,但我不确定如何以编程方式从不变的数据库提供程序名称 (System.Data.OleDb) 检索连接字符串提供程序属性(本示例中为 SQLOLEDB)。

编辑:

你可以做一个

但是返回的 DBConnectionStringBuilder 仍然不知道它的连接字符串提供程序属性,即使在这种情况下它的派生类具有“提供程序”属性。

0 投票
1 回答
3002 浏览

.net - 如何确定 SqlConnection 是否被登记到 System.Transactions 的 tx 中?

默认情况下,当我们使用 System.Transactions 中的事务(为实例创建 TransationScope)时,所有 Sql 连接(System.Data.SqlClient.SqlConnection)(但对于 Oracle.DataAccess.OracleConnection 也不是如此)在打开时被登记. 这称为自动登记。不错的功能。但可以通过连接字符串的参数 (enlist=false) 将其关闭。在这种情况下,将不会征用正在打开的连接。但它可以稍后手动登记。所以我的问题是:对于某些给定的 SqlConnection 实例,我如何确定该连接是否被登记(进入 System.Transaction)。我可以查看参数的连接字符串。但这不会做,因为正如我所说的连接可以手动登记。

0 投票
5 回答
1252 浏览

linq - Persistence framework?

I'm trying to decide on the best strategy for accessing the database. I understand that this is a generic question and there's no a single good answer, but I will provide some guidelines on what I'm looking for. The last few years we have been using our own persistence framework, that although limited has served as well. However it needs some major improvements and I'm wondering if I should go that way or use one of the existing frameworks. The criteria that I'm looking for, in order of importance are:

  1. Client code should work with clean objects, width no database knowledge. When using our custom framework the client code looks like:

    SessionManager session = new SessionManager(); Order order = session.CreateEntity(); order.Date = DateTime.Now; // Set other properties OrderDetail detail = order.AddOrderDetail(); detail.Product = product; // Other properties

    // Commit all changes now session.Commit();

  2. Should as simple as possible and not "too flexible". We need a single way to do most things.

  3. Should have good support for object-oriented programming. Should handle one-to-many and many-to-many relations, should handle inheritance, support for lazy loading.
  4. Configuration is preferred to be XML based.

With my current knowledge I see these options:

  1. Improve our current framework - Problem is that it needs a good deal of effort.
  2. ADO.NET Entity Framework - Don't have a good understanding, but seems too complicated and has bad reviews.
  3. LINQ to SQL - Does not have good handling of object-oriented practices.
  4. nHibernate - Seems a good option, but some users report too many archaic errors.
  5. SubSonic - From a short introduction, it seems too flexible. I do not want that.

What will you suggest?

EDIT:

Thank you Craig for the elaborate answer. I think it will help more if I give more details about our custom framework. I'm looking for something similar. This is how our custom framework works:

  1. It is based on DataSets, so the first thing you do is configure the DataSets and write queries you need there.
  2. You create a XML configuration file that specifies how DataSet tables map to objects and also specify associations between them (support for all types of associations). 3.A custom tool parse the XML configuration and generate the necessary code. 4.Generated classes inherit from a common base class.

To be compatible with our framework the database must meet these criteria:

  1. Each table should have a single column as primary key.
  2. All tables must have a primary key of the same data type generated on the client.
  3. To handle inheritance only single table inheritance is supported. Also the XML file, almost always offers a single way to achieve something.

What we want to support now is:

  • Remove the dependency from DataSets. SQL code should be generated automatically but the framework should NOT generate the schema. I want to manually control the DB schema.
  • More robust support for inheritance hierarchies.
  • Optional integration with LINQ.

I hope it is clearer now what I'm looking for.

0 投票
1 回答
962 浏览

ado.net - 您可以将 ADO.NET SQLCommandBuilder 与复合键一起使用吗?

我有一个包含 6 列的数据库表。主键是由 6 列中的 5 列组成的复合键

我正在尝试使用SqlClient.SqlCommandBuilder.GetDeleteCommand删除该行。

但是我收到以下错误:

“System.InvalidOperationException:对于不返回任何键列信息的 SelectCommand,不支持为 DeleteCommand 生成动态 SQL。”

包含表中的SelectCommmand所有列:

问题可能出在复合键上吗?

0 投票
6 回答
34316 浏览

c# - C# ADO.NET:null 和 DbNull——有更高效的语法吗?

我有一个DateTime?我正在尝试使用DbParameter. 我正在像这样创建参数:

然后我想把 s 的值DateTime?放入dataPrm.Valuewhile 占nulls。

起初我以为我会很聪明:

但这因错误而失败

操作员 '??' 不能应用于“System.DateTime?”类型的操作数?和'System.DBNull'

所以我猜这只有在第二个参数是第一个参数的不可空版本时才有效。所以我去了:

但这也不起作用:

无法确定条件表达式的类型,因为 'System.DateTime' 和 'System.DBNull' 之间没有隐式转换

但我不想在这些类型之间进行转换!

到目前为止,我唯一可以开始工作的是:

这真的是我写这篇文章的唯一方法吗?有没有办法让使用三元运算符的单线工作?

更新:我真的不明白为什么?版本不起作用。MSDN 说:

这 ??运算符如果不为空则返回左操作数,否则返回右操作数。

这正是我想要的!

Update2:嗯,最后很明显: