一:这次是进一步的三层构架,不过还是没有业务逻辑层,但有单独的层的文件夹,解决方案资源管理器图如下:

二:operatorDAl.cs代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using HRMSys.Model;
using System.Data.SqlClient; namespace HRMSys.DAL
{
public class OperatorDAL
{
public void insertUser(Operator op)
{
sqlhelper.ExecuteNon(@"insert into T_Operator (Id,UserName,Password) values (newid(),@UserName,@Password)",
new SqlParameter ("@UserName",op.UserName),
new SqlParameter ("@Password",op.Password));
}
}
}

三:sqlhelper.cs代码

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Configuration; namespace HRMSys.DAL
{
static class sqlhelper
{ /// <summary>
/// 返回受影响的行数
/// </summary>
public static readonly string constr =
ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
public static int ExecuteNon(string sql,params SqlParameter[] parameter )
{
using (SqlConnection conn = new SqlConnection(constr))
{
conn.Open();
using (SqlCommand cmd = conn.CreateCommand())
{
cmd.CommandText = sql;
cmd.Parameters.AddRange(parameter);
return cmd.ExecuteNonQuery(); }
} } /// <summary>
///返回结果的首行首列
/// </summary>
/// <param name="sql"></param>
/// <param name="parameter"></param>
/// <returns></returns>
public static int ExecuteSca(string sql, params SqlParameter[] parameter)
{
using (SqlConnection conn = new SqlConnection(constr))
{
conn.Open();
using (SqlCommand cmd = conn.CreateCommand())
{
cmd.CommandText = sql;
cmd.Parameters.AddRange(parameter);
int result = (int) cmd.ExecuteScalar();
return result;
}
}
} /// <summary>
/// 返回一个数据流
/// </summary>
/// <param name="sql"></param>
/// <param name="parameter"></param>
/// <returns></returns>
public static object SqldataRea(string sql, params SqlParameter[] parameter)
{
using (SqlConnection conn = new SqlConnection(constr))
{
conn.Open();
using (SqlCommand cmd = conn.CreateCommand())
{
cmd.CommandText = sql;
cmd.Parameters.AddRange(parameter);
SqlDataReader sdr= sdr=cmd.ExecuteReader(); return sdr;
}
}
} /// <summary>
/// 返回一个表
/// </summary>
/// <param name="sql"></param>
/// <param name="parameter"></param>
/// <returns></returns>
public static DataTable datatable(string sql, params SqlParameter[] parameter)
{
using (SqlConnection conn = new SqlConnection(constr))
{
conn.Open();
using (SqlCommand cmd = conn.CreateCommand())
{
cmd.CommandText = sql;
cmd.Parameters.AddRange(parameter);
SqlDataAdapter sda = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
sda.Fill(ds);
return ds.Tables[];
}
}
}
}
}

四:operator.cs代码

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text; namespace HRMSys.Model
{
public class Operator
{
public Guid Id { get; set; }
public string UserName { get; set; }
public string Password { get; set; }
}
}

五:form1.cs代码

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using HRMSys.Model;
using HRMSys.DAL; namespace HYMSys.UI
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
/// <summary>
/// 添加一个用户
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void 操作管理员ToolStripMenuItem_Click(object sender, EventArgs e)
{
Operator op = new Operator();
op.UserName = "aaa";
op.Password = ""; OperatorDAL opDal = new OperatorDAL();
opDal.insertUser(op); }
}
}

六:数据库表的建立

七:做这个实例时出现的一个错误,如图:

八:错误的解决,之前由于vs非人为的报错关闭,导致app.config的丢失,我后来又新建了,app1.config,但vs默认读取app.config导致,将之前的app.config添加即可,如图:

vs默认的app.config是哪个?的更多相关文章

  1. C#中怎样获取默认配置文件App.config中配置的键值对内容

    场景 在新建一个程序后,项目中会有一个默认配置文件App.config 一般会将一些配置文件信息,比如连接数据库的字符串等信息存在此配置文件中. 怎样在代码中获取自己配置的键值对信息. 注: 博客主页 ...

  2. 【Core】.NET Core中读取App.config配置文件

    1.项目中添加App.config文件 因为.NET Core的项目本质是控制台应用,所以ConfigurationManager的API会去默认读取app.config配置文件,而不是web.con ...

  3. ASP.NET MVC Filters 4种默认过滤器的使用【附示例】 数据库常见死锁原因及处理 .NET源码中的链表 多线程下C#如何保证线程安全? .net实现支付宝在线支付 彻头彻尾理解单例模式与多线程 App.Config详解及读写操作 判断客户端是iOS还是Android,判断是不是在微信浏览器打开

    ASP.NET MVC Filters 4种默认过滤器的使用[附示例]   过滤器(Filters)的出现使得我们可以在ASP.NET MVC程序里更好的控制浏览器请求过来的URL,不是每个请求都会响 ...

  4. C# 对 App.config的appSettings节点数据进行加密

    .NET平台下的Winform和Asp.net的配置文件默认都是明文保存的,本文使用的是.Net自身如何加密配置文件,不包含自定义的加密规则 但.Net是提供了直接对配置文件加密的功能的,使用.Net ...

  5. App.Config详解及读写操作

    App.Config详解及读写操作   App.Config详解 应用程序配置文件是标准的 XML 文件,XML 标记和属性是区分大小写的.它是可以按需要更改的,开发人员可以使用配置文件来更改设置,而 ...

  6. C#----操作应用程序配置文件App.config

    对配置文件的一些疑问: 在应用程序的目录下,有两处值得注意的地方,一个是应用程序根目录下的App.config文件,和bin\debug\name.exe.config 或者 bin\Release\ ...

  7. C# 读写App.config

    Jul142013 [C#] 读写App.config配置文件的方法 作者:xieyc   发布:2013-07-14 17:29   字符数:3433   分类:编程   阅读: 39,139 次 ...

  8. windows服务 2.实时刷新App.config

    参考 http://www.cnblogs.com/jeffwongishandsome/archive/2011/04/24/2026381.html http://www.cnblogs.com/ ...

  9. C#项目实例中读取并修改App.config文件

    C#项目是指一系列独特的.复杂的并相互关联的活动,这些活动有着一个明确的目标或目的,必须在特定的时间.预算.资源限定内,依据规范完成.项目参数包括项目范围.质量.成本.时间.资源. 1. 向C#项目实 ...

随机推荐

  1. 会话技术之Cookie 和 Session

    为什么要使用会话技术 会话从字面上来说就是,就是两个人说话,也就是两个人交流,那么这里说的是计算机web端的交流,因为互联网是基于HTTP传输信息的,而http传输是无状态协议,缺少状态,意味着如果后 ...

  2. Entity Framework性能优化

    AsNonUnicode 执行如下语句,并用SqlProfiler监控其SQL: var list = WMFactory.ReChargeMobile.Queryable().Where(w =&g ...

  3. 对 JDBC 做一个轻量封装,待完善。。。

    对 JDBC 做一个轻量地封装,顺便复习,熟悉sql,io,util,lang.Reflect等包的使用,泛型的使用,待完善... package com.webproj.utils; import ...

  4. linux du 显示目录下的各个子目录的大小

    use  command du  display estimate file space usage size of subdirectories [oracle@ahjcyl-db backup]$ ...

  5. Object-C 类实现

    这篇为Object-C添加方法的后续. 这里我们应该在类的实现(.m)文件中写 #import "Photo.h" @implementation Photo - (NSStrin ...

  6. jquery自适应布局

    代码整理 - uix.layout.js /** * Grace [jQuery.js] * * UIX页面布局 * 290353142@qq.com * exp: * $.uix.layout(); ...

  7. Codevs 1065 01字符串

    1065 01字符串 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 传送门 题目描述 Description 输出仅有0和1组成的长度为n的字符串,并且其中不能含有 ...

  8. 5shift shell

    echo offcopy %systemroot%\system32\taskmgr.exe %systemroot%\system32\sethc.execopy %systemroot%\syst ...

  9. BOM 之 window

    BOM 之 window 对象 在网页中定义的任何一个对象,变量和函数,都以 window 作为其 Global 对象,因此有权访问别的方法和属性    var age = 26;    functi ...

  10. [Linux]XAMPP安装

    XAMPP安装下载地址:http://xiazai.zol.com.cn/index.php?c=Detail_DetailMini&n=19e18f86d0596b5cd&softi ...