- 浏览: 599959 次
- 性别:
- 来自: 卡哇伊
文章分类
- 全部博客 (299)
- C# (25)
- Java (1)
- WinForm (0)
- Asp.Net (86)
- Jsp (2)
- Php (1)
- Web Service (0)
- Desgin Patterns (19)
- Data Structure & Algorithms (1)
- SQLserver (41)
- Mysql (0)
- Oracle (2)
- Javascript (50)
- Ajax (10)
- Jquery (1)
- Flex (0)
- Regular Expression (5)
- DIV+CSS+XHTML+XML (18)
- Software Test (0)
- Linux (0)
- Utility (17)
- Net Digest (4)
- windows 2003 (10)
- Other (4)
- English (1)
- IT Term (1)
最新评论
-
w497480098h:
学习了 很好谢谢
SQL Server下无限多级别分类查询解决办法(简单查询树形结构数据库表) -
main_fun:
确实不错
iframe自适应高度 -
jveqi:
...
DBA -
mxcie:
其它版本没有确认,今天使用vs2003时,其.sln文件也需要 ...
彻底删除项目的VSS源代码管理信息 -
moneyprosper:
就只有IE支持,火狐和谷歌都不支持此种方法。正在寻找中。。。
从父页面读取和操作iframe中内容方法
存储过程代码
use tempDb go create table study ( id int primary key identity(1,1), name varchar(50), address varchar(50) ) go select * from study go insert into study values ('张三','浙江金华') create procedure study_Query as select * from study go execute study_Query create procedure study_Delete @id int as delete from study where id=@id go create procedure study_Update @id int, @name varchar(50), @address varchar(50) as update study set name=@name,address=@address where id=@id go create procedure study_Insert @name varchar(50), @address varchar(50) as insert into study values (@name,@address) go
布局参考:
.aspx文件:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title>无标题页</title> </head> <body> <form id="form1" runat="server"> <div> <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" Style="margin-right: 1px" DataKeyNames="id,name,address" onrowcancelingedit="GridView1_RowCancelingEdit" onrowdeleting="GridView1_RowDeleting" onrowediting="GridView1_RowEditing" onrowupdating="GridView1_RowUpdating"> <Columns> <asp:BoundField DataField="Id" HeaderText="编号" ReadOnly="true"/> <asp:BoundField DataField="name" HeaderText="名称" /> <asp:BoundField DataField="address" HeaderText="地址" /> <asp:CommandField ShowEditButton="true" EditText="编辑" HeaderText="编辑" /> <asp:CommandField ShowDeleteButton="true" EditText="删除" HeaderText="删除" /> </Columns> </asp:GridView> <br /> 姓名:<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> <br /> 地址:<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox> <br /> <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="提交" /> </div> </form> </body> </html>
.aspx.cs文件
using System; using System.Configuration; using System.Data; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.HtmlControls; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { StudyDataBinds(); } } protected void StudyDataBinds() { this.GridView1.DataSource = DBHelp.GetAllStudy(); this.GridView1.DataBind(); } protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e) { Study study = new Study(); study.Id = Convert.ToInt32(this.GridView1.DataKeys[e.RowIndex][0]); study.Name = (this.GridView1.Rows[e.RowIndex].Cells[1].Controls[0] as TextBox).Text; study.Address = (this.GridView1.Rows[e.RowIndex].Cells[2].Controls[0] as TextBox).Text; DBHelp.UpdStudy(study); this.GridView1.EditIndex = -1; StudyDataBinds(); } protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e) { string id = this.GridView1.DataKeys[e.RowIndex][0].ToString(); Study study = new Study(); study.Id = Convert.ToInt32(id); DBHelp.DelStudy(study); StudyDataBinds(); } protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e) { this.GridView1.EditIndex = -1; StudyDataBinds(); } protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e) { this.GridView1.EditIndex = e.NewEditIndex; StudyDataBinds(); } protected void Button1_Click(object sender, EventArgs e) { Study study = new Study(); study.Name = this.TextBox1.Text; study.Address = this.TextBox2.Text; DBHelp.InsStudy(study); Server.Transfer("~/Default.aspx"); } }
Model:
using System; using System.Data; using System.Configuration; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.HtmlControls; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; /// <summary> ///Study 的摘要说明 /// </summary> [Serializable] public class Study { public Study() { // //TODO: 在此处添加构造函数逻辑 // } private int id; public int Id { get { return id; } set { id = value; } } private string name; public string Name { get { return name; } set { name = value; } } private string address; public string Address { get { return address; } set { address = value; } } }
DBHelp:
using System; using System.Data; using System.Configuration; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.HtmlControls; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Data.SqlClient; using System.Collections; using System.Collections.Generic; /// <summary> ///DBHelp 的摘要说明 /// </summary> public sealed class DBHelp { private static String connString = ConfigurationManager.ConnectionStrings["sql2005"].ConnectionString; public DBHelp() { } /// <summary> /// 查询 /// </summary> /// <returns></returns> public static IList<Study> GetAllStudy() { IList<Study> list = new List<Study>(); using (SqlConnection conn = new SqlConnection(connString)) { conn.Open(); SqlDataAdapter adapter = new SqlDataAdapter(); adapter.SelectCommand = new SqlCommand(); adapter.SelectCommand.Connection = conn; adapter.SelectCommand.CommandText = "study_Query"; adapter.SelectCommand.CommandType = CommandType.StoredProcedure; using (SqlDataReader reader = adapter.SelectCommand.ExecuteReader(CommandBehavior.CloseConnection)) { while (reader.Read()) { Study study = new Study(); study.Id = Convert.ToInt32(reader["id"]); study.Name = Convert.ToString(reader["name"]); study.Address = Convert.ToString(reader["address"]); list.Add(study); } } } return list; } /// <summary> /// 删除 /// </summary> /// <param name="stu"></param> /// <returns></returns> public static int DelStudy(Study stu) { int result; using (SqlConnection conn = new SqlConnection(connString)) { conn.Open(); SqlDataAdapter adapter = new SqlDataAdapter(); adapter.DeleteCommand = new SqlCommand(); adapter.DeleteCommand.CommandText = "study_Delete"; adapter.DeleteCommand.Parameters.Add("@id", SqlDbType.Int).Value = stu.Id; adapter.DeleteCommand.CommandType = CommandType.StoredProcedure; adapter.DeleteCommand.Connection = conn; result = adapter.DeleteCommand.ExecuteNonQuery(); } return result; } /// <summary> /// 更新 /// </summary> /// <param name="stu"></param> /// <returns></returns> public static int UpdStudy(Study stu) { int result; using (SqlConnection conn = new SqlConnection(connString)) { conn.Open(); SqlCommand comm = new SqlCommand(); comm.CommandText = "study_Update"; comm.CommandType = CommandType.StoredProcedure; comm.Parameters.Add("@id", SqlDbType.Int).Value = stu.Id; comm.Parameters.Add("@name", SqlDbType.VarChar, 50).Value = stu.Name; comm.Parameters.Add("@address", SqlDbType.VarChar, 50).Value = stu.Address; comm.Connection = conn; result = comm.ExecuteNonQuery(); } return result; } /// <summary> /// 添加 /// </summary> /// <param name="stu"></param> /// <returns></returns> public static int InsStudy(Study stu) { int result; using (SqlConnection conn = new SqlConnection(connString)) { conn.Open(); SqlCommand comm = new SqlCommand(); comm.CommandText = "study_Insert"; comm.CommandType = CommandType.StoredProcedure; comm.Parameters.Add("@name", SqlDbType.VarChar, 50).Value = stu.Name; comm.Parameters.Add("@address", SqlDbType.VarChar, 50).Value = stu.Address; comm.Connection = conn; result = comm.ExecuteNonQuery(); } return result; } }
通过StoreProcedure得到输出参数和返回值:
create table [user] ( uid int primary key identity, uname varchar(50), upassword varchar(50) ) go insert into [user] values ('张三','123456') insert into [user] values ('李四','123456') insert into [user] values ('王五','123456') set ANSI_NULLS ON set QUOTED_IDENTIFIER ON go create procedure [dbo].[GetNameById] @id int, @name varchar(50) output as begin select @name=uname from [user] where uid=@id return 200 end go
using System; using System.Collections; using System.Configuration; using System.Data; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.HtmlControls; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Data.SqlClient; public partial class Default2 : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { String connString = ConfigurationManager.ConnectionStrings["sql2005"].ToString(); using (SqlConnection conn = new SqlConnection(connString)) { conn.Open(); SqlCommand comm = new SqlCommand(); comm.CommandText = "GetNameById"; comm.Parameters.Add("@id", SqlDbType.Int).Value = 2; //设置输出参数: 增加存储过程输出参数如果是字符型必须制定长度. comm.Parameters.Add("@name", SqlDbType.VarChar, 50).Direction = ParameterDirection.Output; //设置返回值:存储过程的返回值必须是Int型 comm.Parameters.Add("@result", SqlDbType.Int).Direction = ParameterDirection.ReturnValue; /*return值只能是int型,但如果一个nvarchar类型的变量,且该变量中是数字可以隐式地转换为数字时, 那么他将可以作为return值.同理,其他类型变量也一样. 在默认情况下一个存储过程的return value为0,表示这个存储过程被成功的执行,如果是非零值,则代表没有顺利执行. 我们可以认为的返回对自己有用的数据,例如新增一个用户时,返回新增用户的UserID. 用法是:RETURN @usr_id,然后通过.*/ comm.Connection = conn; comm.CommandType = CommandType.StoredProcedure; comm.ExecuteReader(); //得到输入参数 string name = comm.Parameters["@name"].Value.ToString(); //得到返回值 string result = comm.Parameters["@result"].Value.ToString(); Response.Write("输出参数:" + name); Response.Write("<br>"); Response.Write("返回值:" + result); } } }
发表评论
-
JS操作RadioButtonList
2009-12-16 23:25 3842function IsUpPic() { ... -
asp.net跳转页面的三种方法比较
2009-10-22 14:16 24921.Response.redir ... -
ASP.NET网站中的安全问题
2009-10-20 16:57 1149在网络经常看到网站被 ... -
新闻内容页分页的简单做法
2009-10-10 10:08 1188该例子只是提供了基本思路 很简单的做法,这个是假设数 ... -
Asp.net控件开发学习笔记(二)-控件开发基础
2009-10-03 16:49 1306接上篇…….. 看System.Web.UI.Ht ... -
Asp.net控件开发学习笔记-控件开发基础(一)
2009-10-03 16:33 1212服务器控件开发基础 当开发一个服务器控件时,首 ... -
Asp.net用户退出,清空Session,重定向登陆页面
2009-09-28 16:22 4110protected void Page_Load(object ... -
frameset中的aspx无法Postback
2009-09-28 16:07 1456<frameset cols="150,*&q ... -
.net页面定时刷新的几种简单方式
2009-09-28 11:20 58791: window.setTimeout("win ... -
动态添加TextBox
2009-09-21 16:30 1647方法1: 前台代码: <f ... -
浅谈ASP.NET管道优化
2009-09-20 21:43 967ASP.NET管道优化 位于请求管道中的很多ASP.NET默 ... -
Asp.net 页面返回到上一页面
2009-09-20 21:20 866/// <summary> / ... -
PrecompiledApp.config文件和Global.asax 文件中的事件的关联
2009-09-19 10:24 2731在用Microsoft Visual Studio 2005开 ... -
gridview列 数字、货币和日期 显示格式
2009-09-11 17:05 1499在设置gridview等数据绑定控件的模版列时,总要 ... -
ASP.NET 打开新窗口几种方法
2009-09-09 21:44 3277ASP.NET打开新窗口方法一: Response ... -
response.addHeader("Content-Disposition","attachment; filename="+filename)中的中文乱码
2009-08-31 15:10 3166两种解决方法 1.如果web.config里utf-8 直接S ... -
技巧和诀窍:如何在VS 2005 SP1中使用VS的web服务器运行一个相对于根目录“/”的网站
2009-08-31 08:29 826大家常有一个疑问,是 ... -
Request.ServerVariables详细说明及代理
2009-08-14 10:46 2059ServerVariables是环境变量的集合。允许读取HTT ... -
DataList和Repeat无数据时提示暂无数据几种方法
2009-08-11 18:45 25261.放一个label DataTable table ... -
Asp.Net中清空所有textbox的几种方法
2009-08-08 08:53 5145用反射: FieldInfo[] info ...
相关推荐
ASP.NET中ACCESS数据库CRUD简单操作(规范示例)
asp.net mvc3 对数据库的 create read update delete操作源码
asp.net mvc4 easyui CRUD 分页 查询,参见博文http://blog.csdn.net/yjjhk/article/details/42008815
ASP.NET中XML数据文件的CRUD简单操作(规范示例)
使用Asp.Net Web APIReactjs Master Detail CRUD 使用Asp.Net Web APIReactjs Master Detail CRUD。 讨论的内容:Asp.Net Web API 项目创建定义数据库模型在EF Core中添加外键数据库迁移使用CRUD Web方法创建API控制...
AspCrud:使用Asp.net MVC C#的基本CRUD操作
Asp.net 利用OleDb的GetOLEDBSchemaTable方法得到数据库架构信息 用于 Visual Studio .Net 的 IBM DB2 开发外接程序 第2章 并发操作的一致性问题 (2) Using sqlite with .NET Visual Studio 2005 中的新 DataSet ...
使用ASP.NET Web API执行CRUD操作-第2部分
ASP.NET MVC5增删改查,包含LINQ和ADO两种(ADO只实现了List Detail和Delete,Edit留给你自己思考了),LINQ版本实现了完整的CRUD,并且演示了MVC5 的新特性Attribute Route以及异步的修改、删除控制器。 相關討論參...
ASP.NET-Core-2-MVC-CRUD-datatables-jQuery-Plugin 首先实现ASP.NET Core 2 MVC CRUD数据表jQuery插件和EF Core代码的示例实现。你会学什么ASP.NET Core 2 使用ASP.NET Core 2的Web API 使用实体框架(EF)的CRUD ...
本系统是基于Asp.Net框架,利用C#编程语言开发的餐饮管理系统,实现了顾客点餐,统计支付,并有点外卖功能,管理员可以管理菜品(比如上传图片),人事调动(增删改查信息),并配有开发报告。
vs2008和sql2005的一个.NET开发crud实例一个.
自述文件ASP.NET(MVC)ANGULARJS CRUD |中文将数据导出为PDF | 单页申请
ASP.NET三层架构 ASP.NET三层学习\对表格增删改.rar
进进出出 ASP.NET Core 5.0 MVC-CRUD操作,EntityFramework核心示例
博文《ASP.NET: GridView CRUD using Twitter Bootstrap Modal Popup 》中提及的源代码
ASP.NET MVC with Entity Framework and CSS by Lee Naylor 2016 | ISBN: 1484221362 | English | 608 pages | True PDF | 30 MB This book will teach readers how to build and deploy a fully working example ...
ASP.NET MVC5使用WebAPI 2 和 AngularJS进行CRUD操作.pdf
本章主要通过一个完整的示例讲解ASP.NET Core MVC+EF Core对MySQL数据库进行简单的CRUD操作,希望能够为刚入门.NET Core的小伙伴们提供一个完整的参考实例
Evolutility-ASP.net Evolutility是用于在ASP.net和SQL Server或MySQL上运行的CRUD(创建,读取,更新,删除)应用程序的通用Web用户界面。 它完全由元数据驱动,并且可以适应不同的数据库结构。 它的行为可能类似于...