c# - 将一组数据保存到一个单元格
问题描述
我想将数组保存Days
到一个单元格、TimeIn_AM
一个单元格、TimeOut_AM
一个单元格、TimeIn_PM
一个单元格和TimeOut_PM
一个单元格
这是我的课程和保存方法
public class EmployeeSchedule
{
public string EmployeeID { get; set; }
public string RecordID { get; set; }
public Schedule[] Schedule { get; set; }
}
public class Schedule
{
public string Days { get; set; }
public string TimeIn_AM { get; set; }
public string TimeOut_AM { get; set; }
public string TimeIn_PM { get; set; }
public string TimeOut_PM { get; set; }
}
for (int i = 0; i < employeeschedule.Schedule.Length; i++)
{
SqlCommand mycommand = new SqlCommand("WorkSchedule_Save", MyConnection);
mycommand.CommandType = CommandType.StoredProcedure;
mycommand.Parameters.Add("@EmployeeID", SqlDbType.VarChar).Value = employeeschedule.EmployeeID;
mycommand.Parameters.Add("@RecordID", SqlDbType.Int).Value = employeeschedule.RecordID;
mycommand.Parameters.Add("@Days", SqlDbType.VarChar).Value = employeeschedule.Schedule[i].Days;
mycommand.Parameters.Add("TimeIn_AM", SqlDbType.VarChar).Value = employeeschedule.Schedule[i].TimeIn_AM;
mycommand.Parameters.Add("TimeOut_AM", SqlDbType.VarChar).Value = employeeschedule.Schedule[i].TimeOut_AM;
mycommand.Parameters.Add("TimeIn_PM", SqlDbType.VarChar).Value = employeeschedule.Schedule[i].TimeIn_PM;
mycommand.Parameters.Add("TimeOut_PM", SqlDbType.VarChar).Value = employeeschedule.Schedule[i].TimeOut_PM;
}
我希望类中的所有数组都使用1EmployeeID
和 1 ,但是当我保存它时,它会为数组中的每个数据创建一个和。RecordID
Schedule
EmployeeID
RecordID
- 而且,如果我从循环中移动
EmployeeID
and theRecordID
,它会说stored procedure or function [WorkSchedule_Save] has too many arguments
*
这是我要保存的数据
{
"EmployeeID": "1000415",
"RecordID": "1005",
"Schedule": [
{
"Days": "Sunday",
"TimeIn_AM": "",
"TimeOut_AM": "",
"TimeIn_PM": "",
"TimeOut_PM": ""
},
{
"Days": "Monday",
"TimeIn_AM": "9:00",
"TimeOut_AM": "12:00",
"TimeIn_PM": "1:00",
"TimeOut_PM": "5:00"
},
{
"Days": "Tuesday",
"TimeIn_AM": "9:00",
"TimeOut_AM": "12:00",
"TimeIn_PM": "1:00",
"TimeOut_PM": "5:00"
},
{
"Days": "Wednesday",
"TimeIn_AM": "9:00",
"TimeOut_AM": "12:00",
"TimeIn_PM": "1:00",
"TimeOut_PM": "5:00"
},
{
"Days": "Thursday",
"TimeIn_AM": "9:00",
"TimeOut_AM": "12:00",
"TimeIn_PM": "1:00",
"TimeOut_PM": "5:00"
},
{
"Days": "Friday",
"TimeIn_AM": "9:00",
"TimeOut_AM": "12:00",
"TimeIn_PM": "1:00",
"TimeOut_PM": "5:00"
},
{
"Days": "Saturday",
"TimeIn_AM": "",
"TimeOut_AM": "",
"TimeIn_PM": "",
"TimeOut_PM": ""
}
]
}
解决方案
您可以但通常不会在 SQL 中这样做。(顺便说一句,这是一个 SQL 和数据建模问题,而不是 C#)。
您将有几张桌子
1. Employee
2. Record
3. ScheduleEntry
并将零件中的所有详细信息保存到这些表中。此选项实际上是唯一允许您使用 SQL 有效地处理数据的选项。
一个更糟糕的选择是有一个表,其中包含您预期的每个位的列
EmployeeNumber, RecordID, timeInMondayAM, timeOutMondayAM,timeInMondayPM, timeOutMondayPM, ... timeInAMSunday.. etc
.
我当然不推荐的另一个选项是为您的值数组设置一个 Text、JSON 或 XML 的计划列,并以适当的格式将它们存储在那里。
推荐阅读
- mysql - Codeigniter 活动记录返回指定行的列名
- python - 数据框中的条形图
- java - 将Java中的对象列表序列化为json
- r - R Leaflet Shiny:shape_click$id 为 NULL
- jenkins - 如何在 Jenkinsfile 中捕获分支名称
- list - aVdin 8 中的样式列表选择
- codeigniter - 如何在codeigniter中添加外键迁移?
- gremlin - Gremlin 用例 - Int 属性和 coalesce()
- elasticsearch - 如何使 Elasticsearch 匹配包含句号作为单词分隔符的文档
- php - 大商取货不更新