Command调用存储过程小实例
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication1.WebForm1" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="GridView1" runat="server"></asp:GridView>
<asp:Label ID="Label1" runat="server" Text="请输入类别名:"></asp:Label>
<br />
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="添加" OnClick="Button1_Click" />
<br />
</div>
</form>
</body>
</html>
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WebApplication1
{
public partial class WebForm1 : System.Web.UI.Page
{
string db = System.Configuration.ConfigurationManager.ConnectionStrings["GetConnection"].ConnectionString;
protected void Page_Load(object sender, EventArgs e)
{
bind();
}
protected void bind()
{
SqlConnection myConn = new SqlConnection(db);
myConn.Open();
string sqlStr = "select * from classtable";
SqlDataAdapter myDa = new SqlDataAdapter(sqlStr,myConn);
DataSet myDs = new DataSet();
myDa.Fill(myDs);
GridView1.DataSource = myDs;
GridView1.DataKeyNames = new string[] { "classID" };
GridView1.DataBind();
myDa.Dispose();
myDs.Dispose();
myConn.Close();
}
protected void Button1_Click(object sender, EventArgs e)
{
if (this.TextBox1.Text!="")
{
SqlConnection myConn =new SqlConnection(db);
myConn.Open();
SqlCommand myCmd = new SqlCommand("insertClass",myConn);
myCmd.CommandType = CommandType.StoredProcedure;
myCmd.Parameters.Add().Value=this.TextBox1.Text.Trim();
myCmd.ExecuteNonQuery();
myConn.Close();
this.bind();
}
else
{
this.bind();
}
}
}
}
create table classtable
(
classID ,)Primary key,
className )
)
insert into classtable values ('电器类')
insert into classtable values ('鲜花类')
insert into classtable values ('服装类')
insert into classtable values ('家具类')
insert into classtable values ('化妆类')
insert into classtable values ('文具类')
insert into classtable values ('软件光盘')
select * from classtable
--存储过程
use t1
go
create proc InsertClass
())
as
insert into classtable(ClassName) values(@ClassName)
go
Command调用存储过程小实例的更多相关文章
- Web Services调用存储过程简单实例
转:http://www.cnblogs.com/jasenkin/archive/2010/03/02/1676634.html Web Services 主要利用 HTTP 和 SOAP 协议使商 ...
- oracle中job定时调用存储过程的实例
使用job模拟定时从元数据表中抽取指定数据进入目标表的过程. 一.创建元数据表 --create table test_origianl create table test_original_data ...
- 使用CompletionService结合ExecutorService批处理调用存储过程任务实例
此实例为java多线程并发调用存储过程实例,只做代码记载,不做详细描述 1.线程池构造初始化类CommonExecutorService.java package com.pupeiyuan.go; ...
- mysql 存储过程 小实例
咱们先建个表吧 [SQL] 纯文本查看 复制代码 ? 1 2 3 4 5 6 CREATE TABLE `test1` ( `id` int(10) unsigned NOT NULL A ...
- ASP调用存储过程访问SQL Server
ASP调用存储过程访问SQL Server 2011-02-15 10:22:57 标签:asp 数据库 sQL 存储过程 Server ASP和存储过程(Stored Procedures)的文章 ...
- Asp调用存储过程,command.CreateParameter 参数值的类型说明
Asp调用存储过程,command.CreateParameter 参数值的类型说明 Asp调用各种存储过程,包括带参数,无参数,输入输出参数,带返回值等. 1,调用没有参数的存储过程 <% s ...
- 第47篇-解释执行的Java方法调用native方法小实例
举个小实例,如下: public class TestJNI { static { // 程序在加载时,自动加载libdiaoyong.so库 System.loadLibrary("dia ...
- MySQL 存储过程实例 与 ibatis/mybatis/hibernate/jdbc 如何调用存储过程
虽然MySQL的存储过程,一般情况下,是不会使用到的,但是在一些特殊场景中,还是有需求的.最近遇到一个sql server向mysql迁移的项目,有一些sql server的存储过程需要向mysql迁 ...
- mybatis 调用存储过程 返回游标 实例
存储过程示例: create or replace procedure Fsp_Plan_CheckPrj(v_grantno varchar2, v_deptcode number, v_curso ...
随机推荐
- C++学习笔记 知识集锦(二)
1. 命名规范 2. 代码格式 3. QString的判断 4. 对象的判空 5. 隐式接口&显式接口 6. vector&string 7. static 8. const 9. v ...
- AngularJS 2.0
https://angular.io/docs/ts/latest/guide/learning-angular.html QuickStart: git clone https://github.c ...
- iOS,视图相关
1.移除视图的所以子视图 2.自定义视图(UIView) 3.处理悬浮窗口(类似微信视频),等比缩放 4.自定义前面视图(可以手写字) 5.图片拉伸的几种方式,计算文本占用空间大小 6.UILable ...
- 此实现不是 Windows 平台 FIPS 验证的加密算法的一部分
在实用VS编程的时候大家经常会遇到一个问题: 下面小编来为大家提供一个简单的解决方案: 1.在Windows中打开功能里输入regedit,回车打开注册表编辑器: 2.转到路径HKEY_LOCAL_M ...
- linux定时任务的设置 crontab 配置指南
为当前用户创建cron服务 1. 键入 crontab -e 编辑crontab服务文件 例如 文件内容如下: */2 * * * * /bin/sh /home/admin/jiaoben/bu ...
- rc.local文件
rc.local用于自启动一些服务. 查看有哪些自启动服务: cat /etc/rc.local
- mybatis教程
http://www.yihaomen.com/article/java/302.htm
- 浮动【电梯】或【回到顶部】小插件:iElevator.js
iElevator.js 是一个jquery小插件,使用简单,兼容IE6,支持UMD和3种配置方式,比锚点更灵活. Default Options _defaults = { floors: null ...
- backbone实例01
backbonejs往简单说,就是一前端MVC框架,适合用于单页面.复杂的前端逻辑. 直接上代码,里面都有相关注释,重点是理解清楚view.collection.model这三者如何关联调用. < ...
- C# 隐藏标题栏 调整大小 并且移动窗口
隐藏标题栏(窗口属性): 1.设置在该窗体的标题栏中是否显示控件框: this.ControlBox = false; 2.设置在该窗体的标题为空: this.Text = string.Empty; ...