<?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. python与pycharm安装

    1.python install 1.1 下载安装包 -  https://www.python.org/downloads 1.2 installl 1.2.1 双击exe安装文件 1.3 如果安装 ...

  2. Microsoft .NET Framework

    Microsoft .NET Framework是用于Windows的新托管代码编程模型.它将强大的功能与新技术结合起来,用于构建具有视觉上引人注目的用户体验的应用程序,实现跨技术边界的无缝通信,并且 ...

  3. JavaScripts 的bom对象

    bom:即broswer object model(浏览器对象模型),由五个对象组成:        Window:对象表示浏览器中打开的窗口 最顶层对象.       Navigator :浏览器对 ...

  4. airflow docker

    https://github.com/puckel/docker-airflow 镜像介绍:https://hub.docker.com/r/puckel/docker-airflow/ docker ...

  5. 使用Python + Selenium打造浏览器爬虫

    Selenium 是一款强大的基于浏览器的开源自动化测试工具,最初由 Jason Huggins 于 2004 年在 ThoughtWorks 发起,它提供了一套简单易用的 API,模拟浏览器的各种操 ...

  6. nodejs prefix(全局)和cache(缓存)windows下设置

    引:在安装完nodejs后,通过npm下载全局模块默认安装到{%USERDATA%}C:\Users\username\AppData\下的Roaming\npm下,这当然是不太对的默认. 1,安装L ...

  7. shiro默认过滤器

  8. python server

    #!/usr/bin/env python #coding=utf-8 # modifyDate: 20120808 ~ 20120810 # 原作者为:bones7456, http://li2z. ...

  9. cestOs 7安装Jenkins

    首先到https://jenkins.io/download/下载Jenkins的war包,放在tomcat下.启动tomcat. 打开对应url.后要求输入密码. 在服务器vim .jenkins/ ...

  10. centos mysql 实战 第一节课 安全加固 mysql安装

    centos mysql  实战  第一节课   安全加固  mysql安装 percona名字的由来=consultation 顾问+performance 性能=per  con  a mysql ...