[英]How do i pass a muti-column datatable with N number of rows as a CSV?
Assume there is an academic program called Bachelors of Computer Science. 假设有一个名为“计算机科学学士”的学术课程。 Assume it is 4 years assume it has a total of 50 courses spread across 4 years.
假设这是4年,假设它在4年中总共开设了50门课程。 Assume I need to save those 50 courses along with the academic program name, definitely I need to use collections.
假设我需要保存那50门课程以及学术课程名称,当然我需要使用收藏集。
so in the DB there are two tables Academics
table and Courses
table, in this case one row will be saved to Academics
and 50 rows will be saved in Courses
因此,在数据库中有两个表
Academics
表和Courses
表,在这种情况下,一行将被保存到Academics
而50行将被保存在Courses
But assume there is scenario that I was told to use CSV
instead of collections. 但是,假设有人告诉我使用
CSV
而不是集合。 so the stored procedure
has an input variable of type varchar(max)
to accept csv
from client. 因此,
stored procedure
的输入变量类型为varchar(max)
以接受来自客户端的csv
。
Assume I need to include these column in csv
string
for each row of data (assume the 50 courses currently on display on a datagridview
) 假设我需要在每一行数据的
csv
string
包括这些列(假设datagridview
上当前显示的50门课程)
CourseID
YearNo --> when the student has the do this course in 1st year, 2nd year etc.
IsCompulsory --> any course a student select can be either compulsory or an elective
csv
string? csv
字符串中? CSV
string to save colllections like above (multi-columned collections)? CSV
字符串保存像上面那样的集合(多列集合)是否是常见的做法? CSV
strings to store collections, is that a reality? CSV
字符串存储集合,这是现实吗? thanks 谢谢
1) the general solution to put columns in a csv string is this: 1)将列放入csv字符串的一般解决方案是:
SELECT column + ',' FROM table FOR XML PATH('') WHERE condition
2) It is common practice, not sure it's always a good one though 2)这是很普遍的做法,但不确定是否总是好的
3) same as 2 3)与2相同
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.