任何人都可以建议一种在 .NET Web 应用程序中使用 CSV 文件上传来动态创建 SQL 表的简单方法吗?
我已经检查了一些答案,但无法找到有关如何使用用户通过 CSV 文件上传的自定义元数据(或 CSV 文件中的列)创建 SQL 表的具体详细信息。 www.dabbledb.com 提供的一项功能,例如为自定义信息创建在线数据库。 它将是一个基于 Web 的 .NET 应用程序,使用 SQL Server 2005 或 2008 作为后端数据库。
期待您的来信。
谢谢 SA
I have checked a few answers but was unable to find specific details on how we can create a SQL table using custom metadata (or Columns from a CSV file) which is uploaded by a user through a CSV file.
A feature available with www.dabbledb.com, like creating online database for custom information.
It will be a web based .NET application using SQL Server 2005 or 2008 as the backend db.
Look forward to hearing from you.
Thank you
SA
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我最近在做一些非常接近您的要求的事情。就我而言,上传到服务器的 CSV 文件中每一行的数据都存储为“blob”。我使用了 Lumen Works CSV reader 来解析上传的 CSV 文件。它能够读取列标题,您可以去除其中的空格,也可以读取 SQL 数据库表列。
希望这有帮助
印地弗罗兹
I recently worked on something quite close to your requirements. In my case, the data from each row in a CSV file that is uploaded in to the server is stored as a 'blob'. I have used the Lumen Works CSV reader to parse the uploaded CSV file. It has the ability to read the column headers, which you can strip of whitespaces and may to SQL database table columns.
Hope this helps
indyfromoz
如果您使用的是实体属性值数据库,那么您只需在链接到实体的主属性表中添加新列,然后只需在实体的属性值表中分配值。
但是,如果这没有意义,那么您将需要使用 ALTER TABLE 命令并添加新列,但如果您要动态更改表结构,那么您可能需要考虑EAV 数据库结构。
If you are using an entity-attribute-value database then you can just add the new columns in the master attribute table, linked to the entity, then just assign values in the attribute-value table for the entity.
But, if that doesn't make sense then you will want to use the
ALTER TABLE
command and add new columns, but if you are going to be dynamically changing the table structure then you may want to consider an EAV database structure.我们刚刚编写了一个 Perl 程序,它读取 csv,分析每一列中的数据,首先尝试相信第一行是列名称,然后拼凑出一个创建表语句和一堆 0f 插入。我们可以从命令环境或 PHP 内部的系统调用运行它。
We just wrote a perl program that reads the csv, analyzes the data in each column, tries at first to believe that the first line is column names, then cobbles up a create table statement and a bunch 0f inserts. We can run it from a command environment or a system call inside PHP.
这只是我如何执行此操作的一个示例(这意味着它可能充满错误并且错误......)
CSV 文件:
伪代码:
可能很恶心,可能很脏,可能只是做你需要的!
This is just an example how I would do this (which means it possibly is bug ridden and wrong...)
CSV File:
Pseudo Code:
May be disgusting, maybe dirty, may just do what you require!