当前位置:网站首页>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);
}
边栏推荐
- Gauss elimination method and template code
- Decompile and modify the non source exe or DLL with dnspy
- Self study software testing. To what extent can you go out and find a job?
- mysql使用视图报错,EXPLAIN/SHOW can not be issued; lacking privileges for underlying table
- 不得不会的Oracle数据库知识点(四)
- Related configuration commands of Huawei rip
- 2022 Software Test Engineer skill list, please check
- QML add gradient animation during state transition
- [dynamic programming] leetcode 53: maximum subarray sum
- Day05 table
猜你喜欢
Conditional test, if, case conditional test statements of shell script
A dichotomy of Valentine's Day
Regular expression of shell script value
CesiumJS 2022^ 源码解读[8] - 资源封装与多线程
[dynamic programming] leetcode 53: maximum subarray sum
Huawei BFD and NQA
HackTheBox-baby breaking grad
[common error] UART cannot receive data error
Release and visualization of related data
be based on. NETCORE development blog project starblog - (14) realize theme switching function
随机推荐
HackTheBox-baby breaking grad
Introduction to unity shader essentials reading notes Chapter III unity shader Foundation
be based on. NETCORE development blog project starblog - (14) realize theme switching function
Day05 table
Analysis and solution of lazyinitializationexception
The force deduction method summarizes the single elements in the 540 ordered array
打印菱形图案
be based on. NETCORE development blog project starblog - (14) realize theme switching function
A-Frame虚拟现实开发入门
It's OK to have hands-on 8 - project construction details 3-jenkins' parametric construction
[software testing] you haven't mastered these real interview questions of big companies?
2-redis architecture design to use scenarios - four deployment and operation modes (Part 2)
机器学习基础:用 Lasso 做特征选择
C library function int fprintf (file *stream, const char *format,...) Send formatted output to stream
MySQL - use of aggregate functions and group by groups
功能:求5行5列矩阵的主、副对角线上元素之和。注意, 两条对角线相交的元素只加一次。例如:主函数中给出的矩阵的两条对角线的和为45。
What insurance products should be bought for the elderly?
The difference between fetchtype lazy and eagle in JPA
[common error] UART cannot receive data error
Introduction to thread pool