插入一个空的使用数据库表asp.net [英] Insert into an empty database table using asp.net

查看:184
本文介绍了插入一个空的使用数据库表asp.net的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从使用DetailsView控件一个asp.net web应用程序,我可以允许用户将行插入我们的SQL数据库表。但是,如果该表是空的,在DetailsView会发生变动时插模式引发错误。在 System.Collections.ArrayList.InsertRange有发生错误(的Int32指数的ICollection C)10647211

From an asp.net web app using a DetailsView control, I can allow users to insert rows into our SQL database table. However, if the table is empty, the DetailsView will throw an error when it changes to insert mode. There error occurs in System.Collections.ArrayList.InsertRange(Int32 index, ICollection c) +10647211:

说明:当前Web请求的执行过程中发生未处理的异常。有关详情,请堆栈跟踪
  有关错误的信息以及它起源于code。

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

例外详细信息:System.ArgumentNullException:收藏不能为空。参数名:C

Exception Details: System.ArgumentNullException: Collection cannot be null. Parameter name: c

我可以手动创建的DetailsView < EmptyDataTemplate> 插入到特定的表,但我有桌子无数由选定的飞行工作用户。

I can manually create the DetailsView <EmptyDataTemplate> to insert into a specific table, but I'm working with a myriad of tables that are chosen on the fly by the user.

我的DetailsView和GridView控件根据用户选择的表自动生成的意见。我想插入控制,这取决于表的用户选择自动生成文本框​​/标签。

My DetailsView and GridView controls automatically generate views according to the table the user chooses. I would like an insert control which automatically generates text boxes/labels depending on which table the users selects.

有没有一种方法,以避免为每个空表,以便插入创建模板?

Is there a way to avoid having to create templates for each empty table to allow inserts?

编辑:
我DetailsView控件是使用的LinqDataSource,如果我尝试绑定到一个空表,我得到同样的错误ArugmentNullException。

My DetailsView control is using a LinqDataSource, and if I try binding to an empty table, I get the same ArugmentNullException error.

推荐答案

我发现我自己的解决办法,这是一个丑陋的解决方案,但它会做。

I found my own workaround, it's an ugly solution, but it'll do.

我添加了一些SQLDataSources每当用户去执行一个插入一个空表,临时插入的伪记录。具有虚设纪录present允许DetailsView控件数据绑定,然后当它不再需要它被删除。

I added some SQLDataSources which insert temporary dummy records whenever the user goes to make an insert into an empty table. Having a dummy record present allows the DetailsView control to DataBind, and then it gets deleted when it's no longer needed.

这个解决方案将不添加到数据库中的任何新的空表工作。并具有临时伪记录,即使是很短的时间量的影响,并没有完全公知的。

This solution will not work for any new empty tables added to the database. And the effects of having a temporary dummy record, even for a short amount of time, aren't fully known.

这篇关于插入一个空的使用数据库表asp.net的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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