当前位置:网站首页>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);
}
边栏推荐
- Technical practice online fault analysis and solutions (Part 1)
- It's OK to have hands-on 8 - project construction details 3-jenkins' parametric construction
- 在寻求人类智能AI的过程中,Meta将赌注押向了自监督学习
- Five high-frequency questions were selected from the 200 questions raised by 3000 test engineers
- Pytest unit test framework: simple and easy to use parameterization and multiple operation modes
- The first training of wechat applet
- 功能:求5行5列矩阵的主、副对角线上元素之和。注意, 两条对角线相交的元素只加一次。例如:主函数中给出的矩阵的两条对角线的和为45。
- mysql使用视图报错,EXPLAIN/SHOW can not be issued; lacking privileges for underlying table
- Mobile asynchronous sending SMS verification code solution -efficiency+redis
- Query efficiency increased by 10 times! Three optimization schemes to help you solve the deep paging problem of MySQL
猜你喜欢

A dichotomy of Valentine's Day

Alibaba test engineer with an annual salary of 500000 shares notes: a complete set of written tests of software testing
![[common error] UART cannot receive data error](/img/77/6ba56ce6e64beeb73a77d04af5bd0f.jpg)
[common error] UART cannot receive data error

Unity Shader入门精要读书笔记 第三章 Unity Shader基础

MySQL - use of aggregate functions and group by groups

手机异步发送短信验证码解决方案-Celery+redis

Function: find the sum of the elements on the main and sub diagonal of the matrix with 5 rows and 5 columns. Note that the elements where the two diagonals intersect are added only once. For example,

Thinkphp6 integrated JWT method and detailed explanation of generation, removal and destruction

Gauss elimination method and template code

我管你什么okr还是kpi,PPT轻松交给你
随机推荐
Since the "epidemic", we have adhered to the "no closing" of data middle office services
Pratique technique | analyse et solution des défaillances en ligne (Partie 1)
@EnableAsync @Async
[prefix and notes] prefix and introduction and use
求esp32C3板子连接mssql方法
Mobile asynchronous sending SMS verification code solution -efficiency+redis
Software testers, how can you quickly improve your testing skills? Ten minutes to teach you
GUI application: socket network chat room
What is the GPM scheduler for go?
Future source code view -juc series
Query efficiency increased by 10 times! Three optimization schemes to help you solve the deep paging problem of MySQL
C library function int fprintf (file *stream, const char *format,...) Send formatted output to stream
Data mining vs Machine Learning: what is the difference between them? Which is more suitable for you to learn
不得不会的Oracle数据库知识点(三)
All in one 1407: stupid monkey
Five high-frequency questions were selected from the 200 questions raised by 3000 test engineers
HackTheBox-baby breaking grad
Alibaba test engineer with an annual salary of 500000 shares notes: a complete set of written tests of software testing
leetcode 121 Best Time to Buy and Sell Stock 买卖股票的最佳时机(简单)
From functools import reduce -- see the use of reduce function from typical examples