<?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. en-zh(社会问题)social problems

    The world's richest man, Amazon founder Jeff Bezos, and his wife MacKenzie have agreed a record-brea ...

  2. .net Core2建立MVC网站,部署

    1..net Core2使用sqlservver.EFCore,部署在linux上将出错,具体是错原因大概是:连接超时的意思.=>就想测试下linux到底能不能连接sqlserver.是两者技术 ...

  3. Dom4j中getStringValue()和getText()用法的区别

    这两个方法都是获取文本的,区别是: getText()-----获取当前节点的文本内容,如果当前节点下是一个element元素,那返回的就是null. getStringValue------获取当前 ...

  4. Cocos 2d TestCPP 学习

    Cocos 2d testcpp包含了大量的demo, 对于新手学习cocos引擎具有非常大的帮助.因为接下来的开发项目有可能会用到该引擎,所以希望可以利用自己的业余时间提前熟悉起来.该篇文章会记录自 ...

  5. iOS,添加阴影

    self.layer.shadowOpacity = 0.5f; // 0.8深 0.3淡 shadowOpacity数值越大,阴影越浓

  6. day1_jmeter接口测试

    一.Jmeter-http接口脚本: 步骤: 1.添加线程组 2.添加http请求 3.在http请求中写入接口url.路径.请求方式.参数 4.添加查看结果树 5.调用接口.查看返回值 二.Jmet ...

  7. 初识jmeter(2)

    1.层级关系: 聚合报告1记录HTTP请求1的结果: 聚合报告2记录HTTP请求2的结果: 聚合报告记录所有线程组中HTTP请求的结果. 2.线程同时启动(并发) 一是可以在把线程组里面的 Ramp- ...

  8. excel之导出

    1.Maven依赖的jar包 <dependency>     <groupId>org.apache.poi</groupId>     <artifact ...

  9. Java+Selenium 如何参数化验证Table表格数据

    场景: 当我们编写脚本时候,需要验证某个表格某一列数据,或者多个列数据. 如果每验证一个就写一个方法,实在是太费事, 因此我们需要有参数化的思想,把某列数据看成固定的元素,然后去验证即可. 1. 示例 ...

  10. CS0433: 类型“Microsoft.Reporting.WebForms.ReportViewer”同时存在于“c:/WINDOWS/assembly/GAC_MSIL/Microsoft.ReportViewer.WebForms/8.0.0.0_ 标签: cassembly

    CS0433: 类型“Microsoft.Reporting.WebForms.ReportViewer”同时存在于“c:/WINDOWS/assembly/GAC_MSIL/Microsoft.Re ...