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 ...
随机推荐
- ExpandoObject动态类生成属性转json
using System; using System.Collections; using System.Collections.Generic; using System.Collections.O ...
- maven常用插件pom配置
一.问题描述: 部署一个maven打包项目时,jar包,依赖lib包全部手动上传至服务器,然后用maven部署报错:Exception in thread "main" java. ...
- lua 面向对象编程类机制实现
lua no class It is a prototype based language. 在此语言中没有class关键字来创建类. 现代ES6, 已经添加class类. prototype bas ...
- python脚本生成exe可执行文件
1.先安装第三方插件: py2exe. Get py2exe from http://www.py2exe.org/ 在download里下载与自己python对应的版本 2.写一个测试python文 ...
- storage disk
scsi fdisk -l can not display the new disk Rescan the SCSI Bus to Add a SCSI Device Without rebootin ...
- 代码回滚:git reset、git checkout和git revert区别和联系
git reset.git checkout和git revert是你的Git工具箱中最有用的一些命令.它们都用来撤销代码仓库中的某些更改,而前两个命令不仅可以作用于提交,还可以作用于特定文件. 因为 ...
- Leetcode: Valid Word Square
Given a sequence of words, check whether it forms a valid word square. A sequence of words forms a v ...
- C/C++ 结构体 指针 简单输入输出
#include <stdio.h> #include <stdlib.h> struct student{ int num; ]; double dec; }; int ma ...
- Excel 同时打开2个或多个独立窗口
首先win7版本点击[开始]菜单,在输入框里面输入"regedit.exe"打开注册表 然后定位找到该路径HKEY_CLASSES_ROOT \ Excel.Sheet.1 ...
- mac 安装jdk1.5
前期准备 Java安装包 JDK 1.5:Java for Mac OS X 10.5 Update 10(From: Apple) 辅助工具 Pacifist:用于提取*.dmg安装包中的文件(点我 ...