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 ...
随机推荐
- ui-grid
html代码: <html ng-app="myApp"> <head> <meta charset="utf- ...
- matlab直方图均衡,使用向量优化
matlab自带有histeq函数对图像进行直方图均衡 自己写了一个,改成向量化形式,效率提高了一点,但是比自带的还是差很多,差不多9倍 function D = my_histeq(I) [m,n] ...
- storage disk
scsi fdisk -l can not display the new disk Rescan the SCSI Bus to Add a SCSI Device Without rebootin ...
- Syntax highlighting in fenced code blocks
Python @requires_authorization def somefunc(param1='', param2=0): r'''A docstring''' if param1 > ...
- Leetcode: Count The Repetitions
Define S = [s,n] as the string S which consists of n connected strings s. For example, ["abc&qu ...
- 在Page_Loaded下删除PivotItem出错的解决方案
之前我一个例子中出现无法再页面Loaded事件中删除PivotItem的情况,页面会报错 Value does not fall within the expected range. 附图 原因是因为 ...
- 纯html、css3、js的时钟
之前在网上看了一些使用js写的时钟,但感觉实现的方法有点麻烦,所以就自己重新写了一个例子,样子有点丑,但方法比较简单,大家就凑合看吧 其中采用的主要方法是原生js里面的Data(时期)对象,以及它的. ...
- Android仿“守望先锋”加载动画
转载请注明本文出自大苞米的博客(http://blog.csdn.net/a396901990),谢谢支持! 效果图 实现思路 画一个小六边形 按效果图位置画七个小六边形 实现一个小六边形的显示与隐藏 ...
- TCPReplay使用---张子芳
TCPReplay主要功能是将PCAP包重新发送,用于性能或者功能测试.但是在测试环境与原转包系统结构一般是不同的.比如被测试机的二层MAC地址与抓包机器的MAC不同,所以被测试机在二层处理时发现目的 ...
- Java未被捕获的异常该怎么处理
在你学习在程序中处理异常之前,看一看如果你不处理它们会有什么情况发生是很有好处的.下面的小程序包括一个故意导致被零除错误的表达式.class Exc0 { public static void ...