当前位置:网站首页>C import Xls data method summary III (processing data in datatable)
C import Xls data method summary III (processing data in datatable)
2022-07-04 01:11:00 【Xiao Zhong wants to learn!!!】
C# Import .xls Data method summary III ( Handle DataTable Data in )
// above , take Excel All the data in the table is written in dtExcel in
// The next step is before adding to the database , Processing of data in each column of the table
// Traverse dtExcel Every row of data in , According to the college name filled in 、 Grade name 、 The specialty name matches the corresponding ID
Create a new studentVo object , Used for storing processed i The data of
Get the uploaded file line data , Match by getting the field information of the header
Compare the obtained uploaded file line data with 【 Last one 】 Write a value equal to the result of the query database related table, and assign it to the declared studentVo Objects are stored first
If the imported data does not arrive again, the database does not have this data , It will return a prompt indicating where the uploader has a problem
for (int i = 0; i < dtExcel.Rows.Count; i++)
{
DataRow row = dtExcel.Rows[i];
// establish studentVo object , Save the data of each student traversed
studentVo studentVo = new studentVo();
// Query the college according to its name ID
string academeName = row[" college "].ToString().Trim();
try
{
studentVo.AcademeID = dbAcademe.Single(m => m.AcademeName == academeName).AcademeID;
}
catch (Exception e)
{
returnJson.Text = string.Format(" The first {0} Of a student college Information matching error , Please check ", i + 1);
return Json(returnJson, JsonRequestBehavior.AllowGet);
}
// Query the major according to the major name ID
string specialtyName = row[" major "].ToString().Trim();
try
{
studentVo.SpecialtyID = dbSpecialty.Single(m => m.AcademeID == studentVo.AcademeID
&& m.SpecialtyName == specialtyName).SpecialtyID;
}
catch (Exception e)
{
returnJson.Text = string.Format(" The first {0} Of a student major Information matching error , Please check ", i + 1);
return Json(returnJson, JsonRequestBehavior.AllowGet);
}
// Query major according to grade name ID
string gradeName = row[" grade "].ToString().Trim();
try
{
studentVo.GradeID = dbGrade.Single(m => m.AcademeID == studentVo.AcademeID
&& m.GradeName == gradeName).GradeID;
}
catch (Exception e)
{
returnJson.Text = string.Format(" The first {0} Of a student grade Information matching error , Please check ", i + 1);
return Json(returnJson, JsonRequestBehavior.AllowGet);
}
// Query the major according to the class name ID
string className = row[" class "].ToString().Trim();
try
{
studentVo.ClassID = dbClass.Single(m => m.AcademeID == studentVo.AcademeID
&& m.SpecialtyID == studentVo.SpecialtyID && m.GradeID == studentVo.GradeID
&& m.ClassName == className).ClassID;
}
catch (Exception e)
{
returnJson.Text = string.Format(" The first {0} Of a student class Information matching error , Please check ", i + 1);
return Json(returnJson, JsonRequestBehavior.AllowGet);
}
// Authentication ID No
if (!IdCardHelper.CheckIdCard(row[" ID number "].ToString().Trim()))
{
returnJson.Text = string.Format(" The first {0} The ID card information of students is wrong , Please check ", i + 1);
return Json(returnJson, JsonRequestBehavior.AllowGet);
}
// Student ID , full name , ID number & Gender information filling object student
studentVo.StudentNumber = row[" Student number "].ToString().Trim();
studentVo.StudentName = row[" full name "].ToString().Trim();
studentVo.StudentIDNum = row[" ID number "].ToString().Trim();
studentVo.StudentSex = row[" Gender "].ToString().Trim();
studentVo.UniformAuthenticationCode = row[" Unified authentication code "].ToString().Trim();
// Add each piece of student information to studentVo Object list
listStudentVo.Add(studentVo);
}
边栏推荐
- swagger中响应参数为Boolean或是integer如何设置响应描述信息
- Oracle database knowledge points (IV)
- Alibaba test engineer with an annual salary of 500000 shares notes: a complete set of written tests of software testing
- Summary of common tools and technical points of PMP examination
- Understanding of Radix
- 不得不会的Oracle数据库知识点(二)
- Mongodb learning notes: command line tools
- Luogu p1309 Swiss wheel
- About uintptr_ T and IntPtr_ T type
- 2-Redis架构设计到使用场景-四种部署运行模式(下)
猜你喜欢

“疫”起坚守 保障数据中台服务“不打烊”

A-Frame虚拟现实开发入门

Hash table, string hash (special KMP)

HackTheBox-baby breaking grad

在寻求人类智能AI的过程中,Meta将赌注押向了自监督学习

Some other configurations on Huawei's spanning tree

我管你什么okr还是kpi,PPT轻松交给你

MySQL - use of aggregate functions and group by groups

It's OK to have hands-on 8 - project construction details 3-jenkins' parametric construction

手机异步发送短信验证码解决方案-Celery+redis
随机推荐
Day05 table
Luogu p1309 Swiss wheel
老姜的特点
Technical practice online fault analysis and solutions (Part 1)
2-redis architecture design to use scenarios - four deployment and operation modes (Part 2)
Mobile asynchronous sending SMS verification code solution -efficiency+redis
Print diamond pattern
功能:编写函数fun求s=1^k+2^k +3^k + ......+N^k的值, (1的K次方到N的K次方的累加和)。
[error record] configure NDK header file path in Visual Studio (three header file paths of NDK | ASM header file path selection related to CPU architecture)
Characteristics of ginger
Some other configurations on Huawei's spanning tree
Decompile and modify the non source exe or DLL with dnspy
A dichotomy of Valentine's Day
QML add gradient animation during state transition
Avoid playing with super high conversion rate in material minefields
Introduction to A-frame virtual reality development
机器学习基础:用 Lasso 做特征选择
Typescript basic knowledge sorting
我管你什么okr还是kpi,PPT轻松交给你
技术实践|线上故障分析及解决方法(上)