我真正想要做的是我想向 SQL Server 发送一个字符串数组。我正在使用 SQL Server 2008。
这可以标记为重复,但在从 stactoverflow 实施解决方案时,我面临着另一个问题
这是我的 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) 我想根据某些情况/条件在现有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)