<?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. 如何用Eclipse+maven创建servlet 3.0 web 项目

    用eclipse + maven, 选择 maven-archetype-webapp,默认的servlet版本是2.3. 目前servlet版本都已经是3.X. 那有什么办法可以创建servlet ...

  2. MySQL命令:约束

    约束是一种限制,它通过对表的行或列的数据做出限制,来确保表的数据的完整性.唯一性 约束分类: 约束类型与关键字: 主键      PRIMARY KEY 默认值  DEFAULT 唯一      UN ...

  3. 解决eclipse在线安装不了genymotion

    解决eclipse在线安装不了genymotion 2015-8-2阅读161 评论0 今天在网上看见网友说genymotion安卓模拟器是多麽的流畅,比起google自带的那些emulator快十倍 ...

  4. wpf(windos窗体)

    在windos窗体中可以放置各种控件,以及为控件定义事件等等,而窗体的显示可以通过show方法以及showdialog方法.他们的区别是 show:运行程序的时候弹出新窗体,而该新窗体会一闪而过,最小 ...

  5. Chap2:什么是shell[The Linux Command Line]

    shell - a program that takes keyboard commands and passes them to the operating system to carry out ...

  6. Delphi中DLL初始化和退出处理

    来自delphibbs: zhousy_2000, 时间: 2005-09-13 13:53:00, ID: 3203484 <1>利用Unit的Initalization与Finaliz ...

  7. odoo中Python实现小写金额转换为大写金额

    自动将小写的金额数值转换为大写,方便记录 class project_parm(models.Model): def IIf(self, b, s1, s2): if b: return s1 els ...

  8. 《linux 进程管理》- ps/top/kill/nice

    一:进程简述 二:ps 查看进程 语法 ps * -A 列出所有进程,和 -e 同等效果 * -a 列出不和本终端有关系的所有进程 * -w 显示加宽,可以显示较多信息 * -u 显示有效使用者相关的 ...

  9. disruptor的并行用法

    实现EventFactory,在newInstance方法中返回,ringBuffer缓冲区中的对象实例:代码如下: public class DTaskFactory implements Even ...

  10. 【PyQt5-Qt Designer】QSlider滑块

    QSlider滑块 QSlider简介 QSlider小部件提供了一个垂直或水平滑块. 滑块是控制有界值的经典控件.它允许用户沿水平或垂直凹槽移动滑块手柄,并将手柄的位置转换为合法范围内的整数值. Q ...