qingtianyzl

晴天blog(QQ:14493558)
  博客园  :: 新随笔  :: 联系 :: 管理

DBEntry组件使用实例

Posted on 2006-06-10 10:18  晴天  阅读(444)  评论(0)    收藏  举报
<%@ Page language="c#" Codebehind="Insert1.aspx.cs" AutoEventWireup="false" Inherits="RD.Test.Insert1" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
    
<HEAD>
        
<title>Insert1</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 MS_POSITIONING="GridLayout">
        
<form id="Form1" method="post" runat="server">
            
<FONT face="宋体">
                
<asp:Label id="Label1" runat="server">Label</asp:Label>
                
<asp:TextBox id="username" runat="server"></asp:TextBox><br />
                
<asp:Label id="Label2" runat="server">Label</asp:Label>
                
<asp:TextBox id="password" 
                    runat
="server"></asp:TextBox><br />
                
<asp:Label id="Label3" runat="server">Label</asp:Label>
                
<asp:TextBox id="email" 
                    runat
="server"></asp:TextBox><br />
                
<asp:Label id="Label4" runat="server">Label</asp:Label>
                
<asp:TextBox id="answer" 
                    runat
="server"></asp:TextBox><br />
                
<asp:Label id="Label5"  runat="server">Label</asp:Label>
                
<asp:TextBox id="question" 
                    runat
="server"></asp:TextBox><br />
                
<asp:Label id="Label6"  runat="server">开启</asp:Label>
                
<INPUT type="radio" name="status" value="1">开启
                
<INPUT type="radio" name="status" value="0">关闭 <br />
                
<asp:Button id="Button1"  runat="server" Text="新增"></asp:Button></FONT>
        
</form>
    
</body>
</HTML>

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;
using System.Collections.Specialized;

namespace RD.Test
{
    
/// <summary>
    
/// Insert1 的摘要说明。
    
/// </summary>

    public class Insert1 : System.Web.UI.Page
    
{
        
protected System.Web.UI.WebControls.Label Label1;
        
protected System.Web.UI.WebControls.Label Label2;
        
protected System.Web.UI.WebControls.Label Label3;
        
protected System.Web.UI.WebControls.Label Label4;
        
protected System.Web.UI.WebControls.Label Label5;
        
protected System.Web.UI.WebControls.Label Label6;
        
protected System.Web.UI.WebControls.TextBox username;
        
protected System.Web.UI.WebControls.TextBox email;
        
protected System.Web.UI.WebControls.TextBox answer;
        
protected System.Web.UI.WebControls.TextBox question;
        
protected System.Web.UI.WebControls.TextBox password;
        
protected System.Web.UI.WebControls.Button Button1;

        DBEntry.DBInterface entry 
= new DBEntry.OleDb.Helper();
    
        
private void Page_Load(object sender, System.EventArgs e)
        
{
            
// 在此处放置用户代码以初始化页面
        }


        
Web 窗体设计器生成的代码

        
private void Button1_Click(object sender, System.EventArgs e)
        
{
            
方法一(需要添加新的字段---即表单中没有的) End方法一

            
方法二(需要添加新的字段---即表单中没有的) End 方法二

            
方法三(表单中存在数据表中所有的字段) End 方法三


        }


        
private NameValueCollection GetNewColle(NameValueCollection arg)
        
{
            NameValueCollection nvc 
= new NameValueCollection();
            
for(int i=0; i<arg.Count;i++)
            
{
                nvc.Add(arg.GetKey(i),arg[i]);
            }

            nvc.Add(
"PKID",GetNewPKID());
            
return nvc;
        }


        
private string GetNewPKID()
        
{
            
string cmdText = "select top 1 PKID from SysUsers order by PKID desc";
            
string PKID = entry.GetString(cmdText);
            
if(PKID==null) PKID = "1";
            
else PKID = (Int32.Parse(PKID) + 1).ToString();
            
return PKID;
        }

    }

}





<%@ Page language="c#" Codebehind="Update1.aspx.cs" AutoEventWireup="false" Inherits="RD.Test.Update1" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
    
<HEAD>
        
<title>Update1</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 MS_POSITIONING="GridLayout">
        
<form id="Form1" method="post" runat="server">
            
<FONT face="宋体">
                
<asp:Label id="Label1" runat="server">Label</asp:Label>
                
<asp:TextBox id="username" runat="server"></asp:TextBox><br>
                
<asp:Label id="Label2" runat="server">Label</asp:Label>
                
<asp:TextBox id="password" runat="server"></asp:TextBox><br>
                
<asp:Label id="Label3" runat="server">Label</asp:Label>
                
<asp:TextBox id="email" runat="server"></asp:TextBox><br>
                
<asp:Label id="Label4" runat="server">Label</asp:Label>
                
<asp:TextBox id="answer" runat="server"></asp:TextBox><br>
                
<asp:Label id="Label5" runat="server">Label</asp:Label>
                
<asp:TextBox id="question" runat="server"></asp:TextBox><br>
                
<asp:Label id="Label6" runat="server">开启</asp:Label>
                
<INPUT type="radio" name="status" value="1" runat="server" id="rd1">开启 <INPUT type="radio" name="status" value="0" runat="server" id="rd2">关闭
                
<br>
                
<asp:Button id="Button1" runat="server" Text="更新"></asp:Button>
                
<asp:Button id="Button2" style="Z-INDEX: 101; LEFT: 80px; POSITION: absolute; TOP: 160px" runat="server"
                    Text
="删除"></asp:Button></FONT>
        
</form>
    
</body>
</HTML>


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 RD.Test
{
    
/// <summary>
    
/// Update1 的摘要说明。
    
/// </summary>

    public class Update1 : System.Web.UI.Page
    
{
        
protected System.Web.UI.WebControls.Label Label1;
        
protected System.Web.UI.WebControls.TextBox username;
        
protected System.Web.UI.WebControls.Label Label2;
        
protected System.Web.UI.WebControls.TextBox password;
        
protected System.Web.UI.WebControls.Label Label3;
        
protected System.Web.UI.WebControls.TextBox email;
        
protected System.Web.UI.WebControls.Label Label4;
        
protected System.Web.UI.WebControls.TextBox answer;
        
protected System.Web.UI.WebControls.Label Label5;
        
protected System.Web.UI.WebControls.TextBox question;
        
protected System.Web.UI.WebControls.Label Label6;
        
protected System.Web.UI.WebControls.Button Button1;

        DBEntry.DBInterface entry 
= new DBEntry.OleDb.Helper();
        
protected System.Web.UI.HtmlControls.HtmlInputRadioButton rd1;
        
protected System.Web.UI.HtmlControls.HtmlInputRadioButton rd2;
        
protected System.Web.UI.WebControls.Button Button2;
        
string PKID;
    
        
private void Page_Load(object sender, System.EventArgs e)
        
{
            PKID 
= Request.QueryString["PKID"];

            
if(!Page.IsPostBack)
            
{
                
string cmdText = "select * from SysUsers where PKID=" + PKID;
                DataSet ds 
= entry.GetDataSet(cmdText);
                
if(ds!=null)
                
{
                    
if(ds.Tables[0].Rows.Count>0)
                    
{
                        DataRow dr 
= ds.Tables[0].Rows[0];
                        username.Text 
= dr["username"].ToString();
                        password.Text 
= dr["password"].ToString();
                        email.Text 
= dr["email"].ToString();
                        answer.Text 
= dr["answer"].ToString();
                        question.Text 
= dr["question"].ToString();
                        
if(dr["status"].ToString()=="0") rd2.Checked = true;
                        
else rd1.Checked = true;
                    }

                }


            }

        }


        
Web 窗体设计器生成的代码

        
private void Button1_Click(object sender, System.EventArgs e)
        
{
            
if(entry.Update("SysUsers",Request.Form,"PKID=" + PKID)>0)
            
{
                Response.Write(
"成功!");
            }

            
else
            
{
                Response.Write(
"失败!" + entry.LastError);
            }

        }


        
private void Button2_Click(object sender, System.EventArgs e)
        
{
            
if(entry.Delete("SysUsers","PKID=" + PKID)>0)
            
{
                Response.Write(
"成功!");
            }

            
else
            
{
                Response.Write(
"失败!" + entry.LastError);
            }

        }

    }

}

60多年前,一个朋友给我讲了一个笑话,把我笑翻了,后来由于肚子太疼进了医院。医生给我做手术前,问我 为什么笑成这样,我就讲给他听。他听后狂笑不止,最后竟然笑死了。 我被送上了法庭。法官让我把那个笑话讲出来,由陪审团判定是否与过失杀人的事实要件符合,我要求签订免责合同。法官宣布休庭,一天后重新开庭,宣布接纳我的意见。于是,我当庭把那个笑话讲了出来,结果有人笑得敲桌子,有人笑得在地上打滚。后来,当天所有听到这个笑话的人都笑死了。 我瞬间成了名人,各路记者纷纷要求采访我,我知道这笑话讲出去可能构成公共侵害,于是对着镜头,我含糊地说了一番话,大意就是:“理由永远是谎言,信仰永远是自慰。节目播出后,引起巨大反响。可没想到,有一天,几个神秘便衣闯进我的卧室,把我连拖带拽拉到一个黑屋子里。过了好久,一束强光照到我脸上。我勉强睁开眼睛,惊呆了,坐在我面前的人是目前惟一与我一样家喻户晓的人——总统。 总统大致交待了抓我的目的,很简单:把这个笑话录下来,然后送到中东敌对国家的独裁者那儿,笑死他。我只好答应他的要求,同时提出此笑话属于大规模杀伤性武器,不可针对平民。总统答应了。 两星期后,总统宣布已经掌握了那个笑话的关键技术,并且在沙漠地区试用成功。这在国际间引起轩然大波,很多国家惊慌失措,国际军事学家将此命名为“笑威慑”。就在此时,东方一个国家突然宣布也掌握了该笑话,原来给我讲笑话的那哥们投靠了该国。于是,我们之间形成了“笑威慑平衡”。 三年后,4月1日,我终日担心的终于发生了:中东一个恐怖组织盗取了那个笑话的原始技术。结果,文明遭到前所未有的破坏,各国政府惶惶不可终日。联合国只好召开全球首脑大会,最后将4月1日设定为愚人节。 60多年过去了,我已经风烛残年。在离开世界之前,作为历史见证人,我想有必要把这个笑话讲给大家。那天,我朋友给我讲的这个笑话很简单,很短,就一句话: http://www.tf-studio.com/WORK/FUN/15.HTML 必须回复后,才能查看