惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

人人都是产品经理
人人都是产品经理
博客园_首页
博客园 - 三生石上(FineUI控件)
V
Visual Studio Blog
Hugging Face - Blog
Hugging Face - Blog
美团技术团队
小众软件
小众软件
T
Tailwind CSS Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
月光博客
月光博客
有赞技术团队
有赞技术团队
WordPress大学
WordPress大学
博客园 - 【当耐特】
Apple Machine Learning Research
Apple Machine Learning Research
罗磊的独立博客
V
V2EX
酷 壳 – CoolShell
酷 壳 – CoolShell
IT之家
IT之家
量子位
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Recent Announcements
Recent Announcements
M
MIT News - Artificial intelligence
阮一峰的网络日志
阮一峰的网络日志
The GitHub Blog
The GitHub Blog

博客园 - Kangaroo

IList<T>与Xml互相转换 jQTreeTable在Asp.net中的应用 通用附件上传方法 window.createPopup()创建菜单 - Kangaroo - 博客园 客户端全部选中或取消DataGrid中的CheckBox 事务的回滚设置(SET XACT_ABORT) 获取所有命名的服务器变量的名称和值 服务端返回操作结果消息的方法 - Kangaroo - 博客园 Treeview的文件目录配置 - Kangaroo - 博客园 用层(DIV)来实现弹出窗口 一个实用的表格(锁定表头,可调整单元格大小,可排序) showModalDialog()、showModelessDialog()方法使用详解 SQL Server .NET Framework 数据提供程序连接池 iBATIS.NET 学习笔记(十一) iBATIS.NET 学习笔记(十) iBATIS.NET 学习笔记(九) iBATIS.NET 学习笔记(八) iBATIS.NET 学习笔记(六) iBATIS.NET 学习笔记(五)
iBATIS.NET 学习笔记(七)
Kangaroo · 2006-07-19 · via 博客园 - Kangaroo

用iBATIS.NET读取单条记录,并对这条记录进行修改。
修改Maps/Customers.xml文件,在statements标记中添加下面代码:

<update id="UpdateCustomer" parameterClass="Customers">
        update Customers set 
        CompanyName=#CompanyName#,
        ContactName=#ContactName#,
        ContactTitle=#ContactTitle#,
        Address=#Address#,
        City=#City#,
        Region=#Region#,
        PostalCode=#PostalCode#,
        Country=#Country#,
        Phone=#Phone#,
        Fax=#Fax#
        where CustomerID=#CustomerID#
        
</update>
        
        
<statement id="SelectCustomer" parameterClass="string" resultClass="Customers">
        select 
        CustomerID as CustomerID,
        CompanyName as CompanyName,
        ContactName as ContactName,
        ContactTitle as ContactTitle,
        Address as Address,
        City as City,
        Region as Region,
        PostalCode as PostalCode,
        Country as Country,
        Phone as Phone,
        Fax as Fax
        from Customers where CustomerID=#value#
        
</statement>

新建Web页面,Test3.aspx

<%@ Page language="c#" Codebehind="Test3.aspx.cs" AutoEventWireup="false" Inherits="IbatisNet.Example.Test3" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
    
<HEAD>
        
<title>Test3</title>
        
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
        
<meta name="CODE_LANGUAGE" Content="C#">
        
<meta name="vs_defaultClientScript" content="JavaScript">
        
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
    
</HEAD>
    
<body>
        
<form id="Form1" method="post" runat="server">
            
<h1><P><FONT face="宋体">修改数据库中的记录</FONT></P>
                
<P><FONT face="宋体">
                        
<TABLE id="Table1" cellSpacing="1" cellPadding="1" width="300" border="0">
                            
<TR>
                                
<TD>CustomerID</TD>
                                
<TD>
                                    
<asp:TextBox id="txtID" runat="server" MaxLength="5" ReadOnly="True"></asp:TextBox></TD>
                            
</TR>
                            
<TR>
                                
<TD>CompanyName</TD>
                                
<TD>
                                    
<asp:TextBox id="txtComName" runat="server"></asp:TextBox></TD>
                            
</TR>
                            
<TR>
                                
<TD>ContactName</TD>
                                
<TD>
                                    
<asp:TextBox id="txtContName" runat="server"></asp:TextBox></TD>
                            
</TR>
                            
<TR>
                                
<TD>ContactTitle</TD>
                                
<TD>
                                    
<asp:TextBox id="txtContTitle" runat="server"></asp:TextBox></TD>
                            
</TR>
                            
<TR>
                                
<TD>Address</TD>
                                
<TD>
                                    
<asp:TextBox id="txtAddress" runat="server"></asp:TextBox></TD>
                            
</TR>
                            
<TR>
                                
<TD>City</TD>
                                
<TD>
                                    
<asp:TextBox id="txtCity" runat="server"></asp:TextBox></TD>
                            
</TR>
                            
<TR>
                                
<TD>Region</TD>
                                
<TD>
                                    
<asp:TextBox id="txtRegion" runat="server"></asp:TextBox></TD>
                            
</TR>
                            
<TR>
                                
<TD>PostalCode</TD>
                                
<TD>
                                    
<asp:TextBox id="txtPostal" runat="server"></asp:TextBox></TD>
                            
</TR>
                            
<TR>
                                
<TD>Country</TD>
                                
<TD>
                                    
<asp:TextBox id="txtCountry" runat="server"></asp:TextBox></TD>
                            
</TR>
                            
<TR>
                                
<TD>Phone</TD>
                                
<TD>
                                    
<asp:TextBox id="txtPhone" runat="server"></asp:TextBox></TD>
                            
</TR>
                            
<TR>
                                
<TD>Fax</TD>
                                
<TD>
                                    
<asp:TextBox id="txtFax" runat="server"></asp:TextBox></TD>
                            
</TR>
                            
<TR>
                                
<TD align="center" colSpan="2">
                                    
<asp:Button id="btnSave" runat="server" Text="保存"></asp:Button></TD>
                            
</TR>
                        
</TABLE>
                    
</FONT>
                
</P>
            
</h1>
            
<asp:Label id="lbMessage" runat="server" ForeColor="Red"></asp:Label>
        
</form>
    
</body>
</HTML>

Test3.aspx.cs

//*****************************************************************
//*组织机构:
//*模块名称:
//*模块功能:
//*创建者  : YK
//*创建时间:
//*修改者  :
//*修改时间:
//*****************************************************************
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace IbatisNet.Example
{
    
/// <summary>
    
/// Test3 的摘要说明。
    
/// </summary>

    public class Test3 : System.Web.UI.Page
    
{
        
protected System.Web.UI.WebControls.TextBox txtID;
        
protected System.Web.UI.WebControls.TextBox txtComName;
        
protected System.Web.UI.WebControls.TextBox txtContName;
        
protected System.Web.UI.WebControls.TextBox txtContTitle;
        
protected System.Web.UI.WebControls.TextBox txtAddress;
        
protected System.Web.UI.WebControls.TextBox txtCity;
        
protected System.Web.UI.WebControls.TextBox txtRegion;
        
protected System.Web.UI.WebControls.TextBox txtPostal;
        
protected System.Web.UI.WebControls.TextBox txtCountry;
        
protected System.Web.UI.WebControls.TextBox txtPhone;
        
protected System.Web.UI.WebControls.TextBox txtFax;
        
protected System.Web.UI.WebControls.Button btnSave;
        
protected System.Web.UI.WebControls.Label lbMessage;
    
        
private void Page_Load(object sender, System.EventArgs e)
        
{
            
// 在此处放置用户代码以初始化页面
            if(!Page.IsPostBack) {
                IbatisNet.Example.Model.Customers customer 
= new IbatisNet.Example.Model.Customers();
                
//HZZKE是Customer的CustomerID
                customer = IbatisNet.Example.Mapper.Instance().QueryForObject("SelectCustomer","HZZKE"as IbatisNet.Example.Model.Customers ;
                
this.txtAddress.Text = customer.Address;
                
this.txtCity.Text = customer.City;
                
this.txtComName.Text = customer.CompanyName;
                
this.txtContName.Text = customer.ContactName;
                
this.txtContTitle.Text = customer.ContactTitle;
                
this.txtCountry.Text = customer.Country;
                
this.txtFax.Text = customer.Fax;
                
this.txtID.Text = customer.CustomerID;
                
this.txtPhone.Text = customer.Phone;
                
this.txtPostal.Text = customer.PostalCode;
                
this.txtRegion.Text = customer.Region;
                 
            }

        }


        
Web 窗体设计器生成的代码

        
private void btnSave_Click(object sender, System.EventArgs e) {
            IbatisNet.Example.Model.Customers customer 
= new IbatisNet.Example.Model.Customers();
            customer.CustomerID 
= this.txtID.Text;
            customer.CompanyName 
= this.txtComName.Text;
            customer.ContactName 
= this.txtContName.Text;
            customer.ContactTitle 
= this.txtContTitle.Text;
            customer.Country 
= this.txtCountry.Text;
            customer.Fax 
= this.txtFax.Text;
            customer.Phone 
= this.txtPhone.Text;
            customer.PostalCode 
= this.txtPostal.Text;
            customer.Region 
= this.txtRegion.Text;
            customer.Address 
= this.txtAddress.Text;
            customer.City 
= this.txtCity.Text;
            
try {
                IbatisNet.Example.Mapper.Instance().Update(
"UpdateCustomer",customer);
                
this.lbMessage.Text="记录修改成功!";
            }

            
catch(Exception ex) {
                
this.lbMessage.Text="记录修改出错"+ex.Message;     
            }

        }

    }

}