Asp.net简单三层+Sqllite 增删改查
- 新建项目à新建一个空白解决方案
- 在Model新建一个实体类
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace factory.Model
- {
- public class factorys
- {
- //ID INTEGER PRIMARY KEY AUTOINCREMENT
- // NOT NULL
- // DEFAULT 1,
- //correspondent NVARCHAR( 100 ) COLLATE NOCASE,
- //contactaddress NVARCHAR( 100 ) COLLATE NOCASE,
- //contacts NVARCHAR( 50 ) COLLATE NOCASE,
- //contactway NVARCHAR( 50 ) COLLATE NOCASE,
- //contactposition NVARCHAR( 50 ),
- //dutydepartment NVARCHAR( 50 ),
- //dutyofficer NVARCHAR( 50 ) COLLATE NOCASE,
- //note NVARCHAR( 2000 ) COLLATE NOCASE
- private int _ID;
- public int ID
- {
- get { return _ID; }
- set { _ID = value; }
- }
- /// <summary>
- /// 客户单位
- /// </summary>
- private string _correspondent;
- public string Correspondent
- {
- get { return _correspondent; }
- set { _correspondent = value; }
- }
- /// <summary>
- /// 联系地址
- /// </summary>
- private string _contactaddress;
- public string Contactaddress
- {
- get { return _contactaddress; }
- set { _contactaddress = value; }
- }
- /// <summary>
- /// 联系人
- /// </summary>
- private string _contacts;
- public string Contacts
- {
- get { return _contacts; }
- set { _contacts = value; }
- }
- /// <summary>
- /// 联系方式
- /// </summary>
- private string _contactway;
- public string Contactway
- {
- get { return _contactway; }
- set { _contactway = value; }
- }
- /// <summary>
- /// 联系人职务
- /// </summary>
- private string _contactposition;
- public string Contactposition
- {
- get { return _contactposition; }
- set { _contactposition = value; }
- }
- /// <summary>
- /// 负责部门
- /// </summary>
- private string _dutydepartment;
- public string Dutydepartment
- {
- get { return _dutydepartment; }
- set { _dutydepartment = value; }
- }
- /// <summary>
- /// 负责人
- /// </summary>
- private string _dutyofficer;
- public string Dutyofficer
- {
- get { return _dutyofficer; }
- set { _dutyofficer = value; }
- }
- /// <summary>
- /// 备注
- /// </summary>
- private string _note;
- public string Note
- {
- get { return _note; }
- set { _note = value; }
- }
- }
- }
- 右击解决方案名称à新建一个DAL与BLL ,Model类库,因为个人习惯建好每个类库时喜欢à右击类库属性à默认命名空间将factoryModel改为àfactory.Model所以应用命名空间时为
- using factory.Model;
- 如果不更改则为
- using factoryModel;
- 新建一个Windows窗体应用程序(UI层)
- 添加引用 : 因为用的是SQLite数据库所以要手动添加一个SQLite的dll引用文件,在解决方案下新建一个lib文件夹将SQLite的dll文件添加进去
DAL引用Model,与新建的lib文件下的SQLite.dll 及
BLL引用DAL,Model与Model UI引用DAL与Model - DAL下的ado.net SqlliteHelper.cs
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Configuration;
- using System.Data.SQLite;
- using System.Data;
- namespace factory.DAL
- {
- public class SqlliteHelper
- {
- //连接字符串
- private static readonly string str = ConfigurationManager.ConnectionStrings["conStr"].ConnectionString;
- //方法
- /// <summary>
- /// 增删改 都可以
- /// </summary>
- /// <param name="sql">sql语句</param>
- /// <param name="ps">sql语句中的参数</param>
- /// <returns>返回受影响的行数</returns>
- public static int ExecuteNonQuery(string sql, params SQLiteParameter[] ps)
- {
- try
- {
- using (SQLiteConnection con = new SQLiteConnection(str))
- {
- using (SQLiteCommand cmd = new SQLiteCommand(sql, con))
- {
- if (ps != null)
- {
- cmd.Parameters.AddRange(ps);
- }
- con.Open();
- return cmd.ExecuteNonQuery();
- }
- }
- }
- catch (Exception ex)
- {
- throw ex;
- }
- }
- /// <summary>
- /// 查询首行首列
- /// </summary>
- /// <param name="sql">sql语句</param>
- /// <param name="ps">参数</param>
- /// <returns>首行首列object</returns>
- public static object ExecuteScalar(string sql, params SQLiteParameter[] ps)
- {
- try
- {
- using (SQLiteConnection con = new SQLiteConnection(str))
- {
- using (SQLiteCommand cmd = new SQLiteCommand(sql, con))
- {
- con.Open();
- if (ps != null)
- {
- cmd.Parameters.AddRange(ps);
- }
- return cmd.ExecuteScalar();
- }
- }
- }
- catch (Exception ex)
- {
- throw ex;
- }
- }
- /// <summary>
- /// 查询的
- /// </summary>
- /// <param name="sql"></param>
- /// <param name="ps"></param>
- /// <returns></returns>
- public static SQLiteDataReader ExecuteReader(string sql, params SQLiteParameter[] ps)
- {
- SQLiteConnection con = new SQLiteConnection(str);
- try
- {
- using (SQLiteCommand cmd = new SQLiteCommand(sql, con))
- {
- if (ps != null)
- {
- cmd.Parameters.AddRange(ps);
- }
- try
- {
- con.Open();
- return cmd.ExecuteReader(System.Data.CommandBehavior.CloseConnection);
- }
- catch (Exception ex)
- {
- con.Close();
- con.Dispose();
- throw ex;
- }
- }
- }
- catch (Exception ex)
- {
- throw ex;
- }
- }
- /// <summary>
- /// 查询的是一个表
- /// </summary>
- /// <param name="sql">sql语句</param>
- /// <param name="ps">sql语句中的参数</param>
- /// <returns>一个表</returns>
- public static DataTable ExecuteTable(string sql, params SQLiteParameter[] ps)
- {
- try
- {
- DataTable dt = new DataTable();
- using (SQLiteDataAdapter sda = new SQLiteDataAdapter(sql, str))
- {
- if (ps != null)
- {
- sda.SelectCommand.Parameters.AddRange(ps);
- }
- sda.Fill(dt);
- }
- return dt;
- }
- catch (Exception ex)
- {
- throw ex;
- }
- }
- }
- }
- App.config配置文件
- <?xml version="1.0" encoding="utf-8" ?>
- <configuration>
- <startup useLegacyV2RuntimeActivationPolicy="true">
- <supportedRuntime version="v4.0"/>
- </startup>
- <connectionStrings>
- <add connectionString="Data Source=factory.db;Version=3;" name="conStr"/>
- </connectionStrings>
- </configuration>
- SQLite数据库文件就放在UI的binàdebug目录下
- 最后说下参数是

- 完整图片
- 这是本人第一次写博客,主要还是以记录为主,如有其它不当之处还望指点
- 源码下载
- SQLite第三方编辑工具(sqlitestudio)
Asp.net简单三层+Sqllite 增删改查的更多相关文章
- Asp.Net操作MySql数据库增删改查
Asp.Net操作MySql数据库增删改查,话不多说直接步入正题.git源码地址:https://git.oschina.net/gxiaopan/NetMySql.git 1.安装MySQL数据库 ...
- salesforce 零基础开发入门学习(六)简单的数据增删改查页面的构建
VisualForce封装了很多的标签用来进行页面设计,本篇主要讲述简单的页面增删改查.使用的内容和设计到前台页面使用的标签相对简单,如果需要深入了解VF相关知识以及标签, 可以通过以下链接查看或下载 ...
- 【Mybatis】简单的mybatis增删改查模板
简单的mybatis增删改查模板: <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE map ...
- 【转载】salesforce 零基础开发入门学习(六)简单的数据增删改查页面的构建
salesforce 零基础开发入门学习(六)简单的数据增删改查页面的构建 VisualForce封装了很多的标签用来进行页面设计,本篇主要讲述简单的页面增删改查.使用的内容和设计到前台页面使用的 ...
- 最简单的mybatis增删改查样例
最简单的mybatis增删改查样例 Book.java package com.bookstore.app; import java.io.Serializable; public class Boo ...
- 关于C#三层架构增删改查中的“删除”问题
序: 刚学习C#,经过一段时间学习,现在正在做一个简单的前后台联通的项目(主要是C#三层架构实现增删改查).分享一点儿小经验,也供自己以后可以回头看看自己的码农之路. 内容: 主要分享的是一条删除会用 ...
- 【ASP.NET MVC】jqGrid 增删改查详解
1 概述 本篇文章主要是关于JqGrid的,主要功能包括使用JqGrid增删查改,导入导出,废话不多说,直接进入正题. 2 Demo相关 2.1 Demo展示 第一部分 第二部分 2.2 ...
- SQL简单语句(增删改查)
简单的SQL语句增删改查操作 说明: 在mysql里面亲测结果正确 用到的表(学生表:studnets) 1.创建一个学生表,(学号,姓名,性别,家庭住址) mysql> create t ...
- KbmMemTable的简单应用(增删改查示例)
//kbmMemTable unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graph ...
随机推荐
- 【Xamarin挖墙脚系列:Xamarin4.0的重大变更】
原文:[Xamarin挖墙脚系列:Xamarin4.0的重大变更] Windows下的变更不大,主要还是bug 的修复,性能的优化,API的扩展实现. 变化最大的是在Mac上的那个Xamarin.iO ...
- XtraForm中OfficeSkins以及BonusSkin皮肤的设置
前提 http://www.cnblogs.com/chucklu/p/4786629.html 在上一篇文章的基础上,现在来使用其他主题的皮肤 一.其他皮肤主题 一共有3种类型的主题: 1.默认的 ...
- BZOJ_4196_[NOI2015]_软件包管理器_(树链剖分)
描述 http://www.lydsy.com/JudgeOnline/problem.php?id=4196 给出一棵树,树上点权为0或1.u权值为1的条件是从根节点到u路径上的所有点权值都为1.u ...
- CentOS升级Python的方法
centOS内核版本为:3.10.101-1.el6.elrepo.x86_64 1,下载Python安装包 wget http://www.python.org/ftp/python/2.7.6/P ...
- Flash Vector例子
var s1:Student = new Student(); var s2:Student = new Student(); var s3:Student = new Student(); s1.n ...
- Enter键提交表单
input type="submit"在360浏览器上不能提交 用了这个 <input type="button" class="btn b ...
- wireshark不仅仅是用来抓包分析网络的;
凡是不找借口,不排弄推诿理由,提高自我,尽量人事; AIX smit(system manager interface tool); formerly alike; derivatives dpkg ...
- Yii framework 应用总结小窍门(转)
1. Yii Framework] 如何获取当前controller的名称? 下面语句就可以获取当前控制器的名称了! Yii::app()->controller->id 2. yii 如 ...
- hdoj 1083 Courses【匈牙利算法】
Courses Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total S ...
- PHP环境配置综合篇
1.WNMP: http://www.wnmp.com.cn/ En: https://www.getwnmp.org/ 2.xampp:https://www.apachefriends.o ...