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 ...
随机推荐
- Jsoup 解析 HTML
Jsoup 文档 方法 要取得一个属性的值,可以使用Node.attr(String key) 方法 对于一个元素中的文本,可以使用Element.text()方法 对于要取得元素或属性中的HTML内 ...
- 【HDOJ】1059 Dividing
多重背包. #include <stdio.h> #include <string.h> #define mymax(a, b) (a>b) ? a:b ]; ]; vo ...
- Android Volley - volley StringRequest編碼問題
有些時候這個類並不能很好的解決中文編碼問題 如果出現亂碼,就 要重寫該類的parseNetworkResponse 方法了. 繼承StringRequest,然後重寫parseNetworkRespo ...
- android studio class org.bouncycastle.asn1.asn1primitive overrides final method equals
好吧 上手as 又遇到一个问题: class org.bouncycastle.asn1.asn1primitive overrides final method equals... 项目运行的是后报 ...
- 迷宫城堡--HDOJ 1269(Tarjan)
迷宫城堡 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submis ...
- Ajax初步实现页面局部内容更替
类似于QQ邮箱的那种局部页面跳转,单页应用常用到,目前很多网页都是这种,但是弊端就是一次加载过多资源,首次加载卡出翔啊
- HDOJ/HDU 1075 What Are You Talking About(字符串查找翻译~Map)
Problem Description Ignatius is so lucky that he met a Martian yesterday. But he didn't know the lan ...
- 如何设置textarea光标默认为第一行第一个字符
判断文本区是否有内容,如果没有那么光标肯定是在第一行第一个为止的,记住,空格回车也算是有内容在的,也会影响光标的位置
- C标准库简单解读
1,程序运行时动态链接共享库; libc(character),libm(math),使用标准库的函数; eg:stdlib.h exit(); size_t数据类型,NULL空指针在头文件stdde ...
- weekend110(Hadoop)的 第三天笔记
(2015年1月17日) 课程目录 01-hdfs源码跟踪之打开输入流 02-hdfs源码跟踪之打开输入流总结 03-mapreduce介绍及wordcount 04-wordcount的编写和提交集 ...