.net core 简单介绍:
.net core 是微软公司推出的一个跨平台 框架 他重写了Clr底层 屏蔽window 的依赖,可以运行window ,linux ,max等系统 效率比.net framework 要高出很多。
简单说明下.net core 的目录
下面是我学习的时候 写的增删改查
先预览 下界面
1.控制器
using HomeMediaFileManageSystemUtilts.Sql;
using Microsoft.AspNetCore.Mvc;
using System.Data.SqlClient;
namespace NetCore.Controllers
{
public class HomeController : Controller
{
public IActionResult Index()
{
return View();
}
/// <summary>
/// 查询
/// </summary>
/// <returns></returns>
public IActionResult GetUser()
{
//切换数据的语句
//SqlHelper.SetConStr();
var sql = @"SELECT* FROM(
SELECT RID = ROW_NUMBER() OVER(ORDER BY ID),*FROM STUDENT
) A
WHERE A.RID BETWEEN 1 AND 20 AND A.STATUS=1";
var ds = SqlHelper.ExecuteDataSetText(sql, null);
return Json(ds);
}
/// <summary>
/// 删除
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
public string DelUserById(int id) {
var msg = default(string);
var sql = "UPDATE STUDENT SET STATUS=0 WHERE Id=@Id";
SqlParameter[] parameters = new SqlParameter[] {
new SqlParameter("@Id",id)
};
var len=SqlHelper.ExecteNonQueryText(sql, parameters);
if (len > 0)
{
msg = "删除成功";
}
else {
msg = "删除失败";
}
return msg;
}
/// <summary>
/// 根据Id查找
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
public IActionResult GetUserById(int id) {
var sql = " SELECT * FROM STUDENT WHERE Id=@Id";
SqlParameter[] parameters = new SqlParameter[] {
new SqlParameter("@Id",id)
};
var ds= SqlHelper.ExecuteDataSetText(sql, parameters);
return Json(ds);
}
/// <summary>
/// 修改
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
public string UpdateUserById(int id,string name,string school,int age) {
string msg = string.Empty;
var sql = "UPDATE STUDENT SET Age=@age,Name=@Name,School=@School WHERE ID=@ID";
SqlParameter[] parameters = new SqlParameter[] {
new SqlParameter("@Id",id),
new SqlParameter("@Age",age),
new SqlParameter("@Name",name),
new SqlParameter("@School",school),
};
var len = SqlHelper.ExecteNonQueryText(sql, parameters);
if (len > 0)
{
msg = "修改成功";
}
else
{
msg = "修改失败";
}
return msg;
}
}
}
2.视图
@{
ViewData["Title"] = "Index";
}
<script src="~/lib/jquery/dist/jquery.js"></script>
<script src="~/js/Home.js"></script>
<style>
#table {
display: none;
}
td {
height: 40px;
text-align: center;
}
tr:hover {
background-color: lightseagreen;
}
#mask-kk {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
z-index: 999;
background: #666;
opacity: 0.5;
filter: alpha(opacity=50)-moz-opacity: 0.5;
display: none;
}
.popup-kk {
position: absolute;
left: 50%;
width: 400px;
height: 300px;
background: #fff;
z-index: 1000;
display: none;
border-radius: 5px;
}
.layoutDiv {
margin-top:20px;
}
.close {
position: absolute;
top: 21px;
right: 20px;
cursor: pointer;
}
</style>
<center>
<h2>.NET Core 增删改查</h2>
<table border="1" cellpadding="0" cellspacing="0" style="width:1200px" id="table">
<tr>
<th>用户编号</th>
<th>用户名</th>
<th>年龄</th>
<th>性别</th>
<th>爱好<