使用C#在SQL Server中插入整数值数组 [英] Insert Array of Integer Values in SQL Server using C#

查看:138
本文介绍了使用C#在SQL Server中插入整数值数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在SQL数据库表中存储一个整数值数组,并将其存储为逗号分隔的值列表。(在一行中)。



有人可以建议一种方法来实现这个目的吗??

I want to store an array of integer values in a SQL database table,And store it as a comma separated list of values.(with in a single row).

Can some one suggest a method to accomplish this..?

推荐答案

如果我正确理解你的问题,如果它是逗号分隔的列表,你可以只转换字符串并将其存储在varchar字段中。



但是,我真的不建议这样做。在我看来,最好的解决方案是将每个值存储为数据库中的单独行。您可能需要一个新表,可能需要主表的外键,但以这种方式存储值将防止将来出现很多问题。例如,考虑您需要更改或删除列表中的值,这需要付出很多努力,并且可能容易出错。
If I understand your question correctly, if it's a comma separated list, you could just convert the list to string and store it in a varchar field.

However, I really wouldn't advice doing this. In my opinion the best solution would be to store each value as a separate row in the database. You may need a new table for that which may need a foreign key to the master table but storing the values this way will prevent a lot of problems in the future. For example consider of you need to change or delete values inside the list, this would require a lot of effort and would probably be error-prone.


这篇关于使用C#在SQL Server中插入整数值数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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