随笔分类 -  .net / SqlServer数据库操作

摘要:use EFDB go --添加学生存储过程--usp_AddStudents 自定义的存储过程name if exists(select * from sysobjects where name='usp_AddStudents') drop procedure usp_AddStudents g 阅读全文
posted @ 2024-07-01 21:52 龙卷风吹毁停车场 阅读(24) 评论(0) 推荐(0) 编辑
摘要:在这点我们需要使用到的sql语句 语法: update 表名 set 某个值=case when @你要修改的值 > 表中的某一个值 then 成立之后要设置的值 else 前面没有成立设置的值 end 举例: 我根据传入的年龄age来设置type为1还是0,1表示成年,0表示未成年 update 阅读全文
posted @ 2024-06-19 16:15 龙卷风吹毁停车场 阅读(35) 评论(0) 推荐(0) 编辑
摘要:ExecuteScalar 方法允许我们查询单一结果,我们来看看什么是单一结果,有那些需要注意的事项 1. 下面是我对 ExecuteScalar 的简单封装,接下来我们看看,如何使用 /// <summary> /// 查询单一结果 /// </summary> /// <param name=" 阅读全文
posted @ 2024-06-19 11:57 龙卷风吹毁停车场 阅读(31) 评论(0) 推荐(0) 编辑
摘要:/// <summary> /// 事务处理 /// </summary> /// <param name="sqlList">sql语句数组</param> /// <returns></returns> /// <exception cref="Exception"></exception> p 阅读全文
posted @ 2024-06-18 09:13 龙卷风吹毁停车场 阅读(18) 评论(0) 推荐(0) 编辑
摘要:using System; using System.Collections.Generic; using System.Data.SqlClient; using System.Linq; using System.Text; using System.Threading.Tasks; using 阅读全文
posted @ 2024-06-14 19:28 龙卷风吹毁停车场 阅读(6) 评论(0) 推荐(0) 编辑
摘要:1. 将从数据库拿到的DataSet数据集转为DataTable类型 DataTable dt = SqlHelper.GetData() 使用: RowFilter来实现筛选功能 赛选出ClassId为我指定 ClassId的数据 dt.DefaultView.RowFilter = "Class 阅读全文
posted @ 2024-06-14 12:35 龙卷风吹毁停车场 阅读(6) 评论(0) 推荐(0) 编辑
摘要:语法: public static DataTable ExecuteTable(string sql) { using (SqlConnection conn = new SqlConnection(connStr)) { conn.Open(); SqlCommand cmd = new Sql 阅读全文
posted @ 2024-06-14 09:34 龙卷风吹毁停车场 阅读(8) 评论(0) 推荐(0) 编辑
摘要:1. 查询平均值语法 select avg(要计算的值) as 别名 from 表名 select 别名=avg(要计算的值) from 表名 2.获取数据总条数 select count(*) as 别名 from 表名 select 别名=count(*) from 表名 以下是举例: publ 阅读全文
posted @ 2024-06-13 17:56 龙卷风吹毁停车场 阅读(414) 评论(0) 推荐(0) 编辑
摘要:/// <summary> /// 获取多个结果集 /// </summary> /// <param name="sql"></param> /// <returns></returns> /// <exception cref="Exception"></exception> public st 阅读全文
posted @ 2024-06-12 09:28 龙卷风吹毁停车场 阅读(11) 评论(0) 推荐(0) 编辑
摘要:1. Update-Database xxxx 把数据库回滚到xxx的状态,迁移脚本不动. 2. Remove-m igration 删除最后一次的迁移脚本 3. Script-Migration 生成迁移SQL代码,有了Update-Database 为什么还要生成SQL, 可以生成版本D到版本F 阅读全文
posted @ 2024-05-30 14:14 龙卷风吹毁停车场 阅读(32) 评论(0) 推荐(0) 编辑
摘要:安装两个NuGet: Microsoft.EntityFrameworkCore.SqlServer Microsoft.EntityFrameworkCore.Tools 1.创建一个Book.cs文件 using System; using System.Collections.Generic; 阅读全文
posted @ 2024-05-30 10:57 龙卷风吹毁停车场 阅读(76) 评论(0) 推荐(0) 编辑
摘要:1.选择要备份的数据库,单机右键 2.选择任务 3选择备份弹出如下界面 4.记住备份路径,(路径不能包含中文,否则会找不到文件) 5.打开另外一台计算机上的sqlserver,新建一个和备份数据库一样的名字数据库 6. 单机右键->点击任务->点击还原->数据库 7.在弹出的窗体中选择 "设备选项" 阅读全文
posted @ 2024-05-23 08:16 龙卷风吹毁停车场 阅读(170) 评论(0) 推荐(0) 编辑
摘要:新建一个CommandInfo.cs 类 using System; using System.Collections.Generic; using System.Data.Common; using System.Linq; using System.Text; using System.Thre 阅读全文
posted @ 2024-05-21 15:00 龙卷风吹毁停车场 阅读(15) 评论(0) 推荐(0) 编辑
摘要:在sql-server设计表格中直接修改无效,目前并不知道为撒不行, 但是可以使用命令的方式修改 alter table 表名 alter column 列名 要修改成的数据类型 列: alter table ClassInfo alter column ClassName varchar(50) 阅读全文
posted @ 2024-05-18 13:46 龙卷风吹毁停车场 阅读(59) 评论(0) 推荐(0) 编辑

点击右上角即可分享
微信分享提示