<?xml version="1.0" encoding="utf-8"?>

 <!--
有关如何配置 ASP.NET 应用程序的详细信息,请访问
http://go.microsoft.com/fwlink/?LinkId=169433
--> <configuration>
<system.web>
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5" />
</system.web>
<connectionStrings>
<add name="connStr" connectionString="server=.;database=web1;uid=sa;pwd=123"/>
</connectionStrings>
</configuration>
 using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web; namespace t3_TypeInfo
{
public static class SqlHelper
{
private static string connStr =
System.Configuration.ConfigurationManager.ConnectionStrings["connStr"].ConnectionString; public static DataTable GetList()
{
using (SqlConnection conn=new SqlConnection(connStr))
{
string sql = "select * from typeinfo order by typeid desc";
SqlDataAdapter sda=new SqlDataAdapter(sql,conn);
DataTable dt=new DataTable();
sda.Fill(dt);
return dt;
}
} public static TypeInfo GetById(int id)
{
using (SqlConnection conn=new SqlConnection(connStr))
{
string sql = "select * from typeinfo where typeid=@id";
SqlParameter p=new SqlParameter("@id",id); SqlCommand cmd=new SqlCommand(sql,conn);
cmd.Parameters.Add(p); conn.Open();
TypeInfo ti=new TypeInfo();
SqlDataReader sdr = cmd.ExecuteReader();
sdr.Read();
ti.TypeId = Convert.ToInt32(sdr["TypeId"]);
ti.TypeTitle = sdr["TypeTitle"].ToString(); return ti;
}
} public static int Add(string title)
{
using (SqlConnection conn = new SqlConnection(connStr))
{
string sql = "insert into typeinfo values(@title)";
SqlParameter p=new SqlParameter("@title",title); SqlCommand cmd=new SqlCommand(sql,conn);
cmd.Parameters.Add(p); conn.Open();
return cmd.ExecuteNonQuery();
}
} public static int Edit(TypeInfo ti)
{
using (SqlConnection conn=new SqlConnection(connStr))
{
string sql = "update typeinfo set typeTitle=@title where typeid=@id";
SqlParameter[] ps =
{
new SqlParameter("@id", ti.TypeId),
new SqlParameter("@title", ti.TypeTitle)
}; SqlCommand cmd=new SqlCommand(sql,conn);
cmd.Parameters.AddRange(ps); conn.Open();
return cmd.ExecuteNonQuery();
}
} public static int Remove(int id)
{
using (SqlConnection conn=new SqlConnection(connStr))
{
string sql = "delete from typeinfo where typeid=@id";
SqlParameter p=new SqlParameter("@id",id); SqlCommand cmd=new SqlCommand(sql,conn);
cmd.Parameters.Add(p); conn.Open();
return cmd.ExecuteNonQuery();
}
}
}
}

003-SqlHelper.cs/Web.config的更多相关文章

  1. 让LinqToSQL使用Web.Config中的链接字符串(修改Settings.Designer.cs)

    [global::System.Configuration.ApplicationScopedSettingAttribute()] [global::System.Diagnostics.Debug ...

  2. ASP.NET程序中动态修改web.config中的设置项目(后台CS代码)

    using System;using System.Collections;using System.ComponentModel;using System.Data;using System.Dra ...

  3. 在Asp.Net MVC 中如何用JS访问Web.Config中appSettings的值

    应用场景: 很多时候我们要在Web.Config中添加appSettings的键值对来标识一些全局的信息,比如:调用service的domain,跳转其他网站页面的url 等等: 那么此时就涉及到了一 ...

  4. web.config设置和取值

    博客园中有一篇文章对web.config的结构做了很详细的介绍,原文见 http://www.cnblogs.com/gaoweipeng/archive/2009/05/17/1458762.htm ...

  5. asp.net中web.config配置节点大全详解

    最近网上找了一些关于Web.config配置节点的文章,发现很多都写的都比较零散,而且很少有说明各个配置节点的作用和用法.搜索了一下发现有一篇写的不错,这里引用一下 原文地址 http://www.c ...

  6. web.config详解 -- asp.net夜话之十一

    1.配置文件节点说明    1.1 <appSettings>节点    1.2 <connectionStrings>节点    1.3 <compilation> ...

  7. 基于.net mvc的校友录(五、web.config对的配置以及filter实现的权限控制)

    web.config配置文件 此文件是整个系统的配置中心,它告诉iis服务器本网站需要哪些运行时环境,需要哪些环境,将要进行哪些操作,开发人员也会将一个常量性的数据放在此配置中,以备系统全局调用.此文 ...

  8. c#与vb.net在App_Code里面编译要通过,需要以下web.config的配置

    web.config的配置: <system.web> <codeSubDirectories> <add directoryName="VB"/&g ...

  9. web.config配置aspx页面默认引用的namespace

    如果我们在aspx页面上使用<%%>的方式使用某些类的时候很多都没办法直接使用,我们必须要在页面上引用命名空间, 如:如果我们要使用DataTable类的时候,我们必须先使用<%@ ...

随机推荐

  1. Mac开发博客摘录

    https://blog.csdn.net/wangyouxiang/article/details/17855255 https://www.cocoacontrols.com/controls?p ...

  2. 两种Python基于OpenCV的固定位置半透明水印去除方案

    1. 基于 inpaint 方法(网上的方法,处理质量较低) 算法理论:基于Telea在2004年提出的基于快速行进的修复算法(FMM算法),先处理待修复区域边缘上的像素点,然后层层向内推进,直到修复 ...

  3. coreseek搜索

    参考文档地址:http://github.tiankonguse.com/doc/sphinx/

  4. Adobe Flex初记

    公司项目要用Flex,之前没有接触过,菜鸟只好白手起家,把项目拉下来的同时配置下Flex的环境,以下是一篇参考: http://blog.sina.com.cn/s/blog_4c4a24db0100 ...

  5. Python中的format函数

    format是python2.6新增的一个格式化字符串的方法,相对于老版的%格式方法,它有很多优点. 1.不需要理会数据类型的问题,在%方法中%s只能替代字符串类型 2.单个参数可以多次输出,参数顺序 ...

  6. ORACLE INSTANCE与EM系统

    Emctl start dbconsole https://192.168.183.132:1158/em/ 复制到游览器进入到em 更改初始化参数值 静态参数: -只能在参数文件中更改 -必须重新启 ...

  7. quartz实现定时任务

    一个定时的demo 引入maven依赖: <dependency> <groupId>org.quartz-scheduler</groupId> <arti ...

  8. TZOJ:玛祖游戏

    描述 玛祖是一款非常经典的游戏,游戏的角色是一只青蛙,青蛙每次可以吐出一颗珠子,如果将珠子吐到场景中相同颜色的珠子旁边(称为击中),当三个或者三个以上的同颜色珠子在一起的时候便可以消掉,如果消掉后还有 ...

  9. 机器Coding For WPF

    declare @modelcode varchar(90)='AutoProjectType'declare @ns varchar(90)='WpfApplication'declare @dat ...

  10. 调用finecms栏目多图怎么实现

    finecms栏目自定义字段添加图集怎么调用出来?已经上传两张图片了,点击可以预览图片,前端显示不了,如下图所示.调用栏目多图这个要涉及到二次开发,首先要先添加栏目自定义字段,设为文件的格式,然后可以 ...