c# - 将 list<> 内容插入 SQL
问题描述
我的代码中有一些函数,它们返回一个包含一些项目的列表。我需要在不同的行中将每个列表组件插入到 SQL 中,但实际上不知道如何。
任何人都可以帮助它吗?我将在下面留下代码
string RecursosInfra = "Email, Impressao, Desktop";
string[] recurso = Regex.Split(RecursosInfra, @"\W+");
List<string> ListaRecursosInfra = new List<string>();
foreach (string valor in recurso)
{
ListaRecursosInfra.Add(valor);
}
要将常用值插入我的 SQL DB,我在 DAL 层中使用了类似的东西:
string id;
AbriConexao();
Tr = Con.BeginTransaction();
String query =
"INSERT INTO[dbo].[TI01A]" +
" ([Name] " +
" ,[Age]) " +
" VALUES " +
" (@Name " +
" ,@Age); " +
" SELECT SCOPE_IDENTITY()";
//string insertedID = dbcm.ExecuteScalar();
//// This will insert the record and also get the id of the inserted record in database
Cmd = new SqlCommand(query, Con, Tr);
Cmd.Parameters.AddWithValue("@Name", s.Name);
Cmd.Parameters.AddWithValue("@Age", s.Age);
id = Cmd.ExecuteScalar().ToString();
//Cmd.ExecuteNonQuery();
Tr.Commit();
return id;
解决方案
推荐阅读
- android - 如何在android中的矩形视图上实现圆角三角形
- c# - Xamarin Forms:加载使用列表视图的 REST API OnItemSelected 的详细信息页面
- node.js - NodeJS 未将 POST 正文发布到 DataDog 日志
- c# - ASP.NET CORE MVC - 来自其他休息的令牌 - 身份验证属性
- node.js - MongoDb:存储时间范围的最佳方式
- java - 如何在 jOOQ 中使用 formatJSON(JSONFormat) 正确格式化生成的 JSON 类型的常规结果?
- javascript - 在 iPad mini 上未正确检测到视口
- java - 如何反序列化动态生成的 JSON 对象?
- javascript - 如何去抖动 Lodash 调用以正确获取 Typescript?
- arrays - MongoDB $lookup 用对象数组替换 _id 数组,而不将数组转换为对象并删除字段