当前位置:网站首页>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);
}
边栏推荐
- HR disgusted interview behavior
- 【.NET+MQTT】.NET6 环境下实现MQTT通信,以及服务端、客户端的双边消息订阅与发布的代码演示
- 7.1 学习内容
- Avoid playing with super high conversion rate in material minefields
- From functools import reduce -- see the use of reduce function from typical examples
- [error record] configure NDK header file path in Visual Studio
- A-Frame虚拟现实开发入门
- In the process of seeking human intelligent AI, meta bet on self supervised learning
- Cesiumjs 2022^ source code interpretation [8] - resource encapsulation and multithreading
- 1-redis architecture design to use scenarios - four deployment and operation modes (Part 1)
猜你喜欢
Technical practice online fault analysis and solutions (Part 1)
Windos10 reinstallation system tutorial
[common error] custom IP instantiation error
2-Redis架构设计到使用场景-四种部署运行模式(下)
The FISCO bcos console calls the contract and reports an error does not exist
Long article review: entropy, free energy, symmetry and dynamics in the brain
On covariance of array and wildcard of generic type
Is it really possible that the monthly salary is 3K and the monthly salary is 15K?
Mobile asynchronous sending SMS verification code solution -efficiency+redis
手机异步发送短信验证码解决方案-Celery+redis
随机推荐
Alibaba test engineer with an annual salary of 500000 shares notes: a complete set of written tests of software testing
Print diamond pattern
1-Redis架构设计到使用场景-四种部署运行模式(上)
Introduction to thread pool
机器学习基础:用 Lasso 做特征选择
Force deduction solution summary 1189- maximum number of "balloons"
功能:求出菲波那契数列的前一项与后一项之比的极限的 近似值。例如:当误差为0.0001时,函数值为0.618056。
Is it really possible that the monthly salary is 3K and the monthly salary is 15K?
What insurance products should be bought for the elderly?
CLP information - how does the digital transformation of credit business change from star to finger?
Related configuration commands of Huawei rip
Future源码一观-JUC系列
The FISCO bcos console calls the contract and reports an error does not exist
Luogu p1309 Swiss wheel
老姜的特点
Function: write function fun to find s=1^k+2^k +3^k ++ The value of n^k, (the cumulative sum of the K power of 1 to the K power of n).
Some other configurations on Huawei's spanning tree
MPLS experiment
On the day when 28K joined Huawei testing post, I cried: everything I have done in these five months is worth it
2-Redis架构设计到使用场景-四种部署运行模式(下)