小编She*_*med的帖子

结构化类型必须至少有一个字段 c#

我真正想要做的是我想向 SQL Server 发送一个字符串数组。我正在使用 SQL Server 2008。

这可以标记为重复,但在从 stactoverflow 实施解决方案时,我面临着另一个问题

链接如何将数组传递到 SQL Server 存储过程

这是我的 C# 和存储过程代码

C#代码:

string[] str = new string[] {"s" , "a" , "k"};

DataTable dt = new DataTable();
dt.Columns.Add("names");

foreach (string item in str)
{
    dt.Rows.Add(item);
}

foreach (DataRow r in dt.Rows)
{
    Console.WriteLine(r["names"].ToString());
}

DataTable tvp = new DataTable();

SqlConnection conn = new SqlConnection("Data Source=SHZAK;Initial Catalog=synchroniztionTesing;Integrated Security=True");
conn.Open();

using (conn)
{
    SqlCommand cmd = new SqlCommand("strpdPassAnStringArray", conn);
    cmd.CommandType = CommandType.StoredProcedure;

    SqlParameter …
Run Code Online (Sandbox Code Playgroud)

c# sql-server stored-procedures table-variable

7
推荐指数
1
解决办法
1万
查看次数

有条件地将具有默认值的列添加到SQL Server中的现有表

我想根据某些情况/条件在现有SQL表中添加具有默认值的新列。

我想知道是否有可能。如果是,怎么办?如果不是,为什么?

替代方案:

一种选择是创建列,然后更新,但是这里的方法是不可能的。

让我们考虑一下下表

?????????????????????
? ID ?      Age     ? 
?????????????????????
?  1 ?    0.166667  ?   
?  2 ?     0.125    ?   
?  3 ?       13     ?   
?  4 ?       19     ?  
?  5 ?       45     ?  
?  6 ?       59     ?   
?  7 ?       60     ?  
?  8 ?       64     ? 
?????????????????????
Run Code Online (Sandbox Code Playgroud)

所需的输出是这样的:

?????????????????????????????????
? ID ?      Age     ? AgeGroup  ?
?????????????????????????????????
?  1 ?    0.166667  ?   NewBorn ?
?  2 ?     0.125    ?   NewBorn ?
?  3 ? …
Run Code Online (Sandbox Code Playgroud)

sql sql-server

-1
推荐指数
1
解决办法
125
查看次数

标签 统计

sql-server ×2

c# ×1

sql ×1

stored-procedures ×1

table-variable ×1