demo_database_vb.aspx
上传用户:lanchensha
上传日期:2022-02-27
资源大小:7530k
文件大小:4k
- <%@Page Language="VB" ValidateRequest="false" ContentType="text/html"%>
- <%@Register TagPrefix="dntb" Namespace="DotNetTextBox" Assembly="DotNetTextBox"%>
- <script runat="server" language="VB">
- Private Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
- If Not IsPostBack Then
- WebEditor1.Text = "<a href=http://www.aspxcn.com.cn><img src='system_dntb/skin/xp/img/logo.gif' alt='DotNet中华网版权所有' width=260 height=60 border=0></a>"
- End If
- End Sub
- Private Sub Button1_OnClick(ByVal sender As Object, ByVal e As System.EventArgs)
- '连接数据库
- Dim lj As New System.Data.OleDb.OleDbConnection("Provider=Microsoft.Jet.OleDb.4.0;Data Source=" + HttpContext.Current.Server.MapPath("demo_database.mdb"))
- '特别注意,这里要用HtmlEncode编码后插入数据库
- Dim ml As New System.Data.OleDb.OleDbCommand("insert into temp(contents) values('" + Server.HtmlEncode(WebEditor1.Text.Replace("'", "''")).Replace("" & Chr(10) & "", "<br />") + "')", lj)
- lj.Open()
- '插入内容到数据库
- ml.ExecuteNonQuery()
-
- '读取数据库
- Dim dr As New System.Data.OleDb.OleDbDataAdapter("select top 1 contents from temp order by id desc", lj)
- Dim ly As New System.Data.DataSet()
- dr.Fill(ly)
-
- '特别注意,这里要用HtmlDecode解码还原后的二进制数据并显示
- label1.Text = "<hr><b>以下是DotNetTextBox控件提交的内容</b>:<br>" + Server.HtmlDecode(Encoding.Unicode.GetString(ly.Tables(0).Rows(0)("contents")))
-
- lj.Close()
-
- End Sub
- Private Sub Button2_OnClick(ByVal sender As Object, ByVal e As System.EventArgs)
- WebEditor1.Text = ""
- End Sub
- </script>
- <!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>
- <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
- <title>演示:提交内容到数据库的应用实例(C#)</title>
- <style type="text/css">
- <!--
- body {
- font-size: 9pt;
- }
- hr {
- border: dotted #AFAFAF;
- }
- input {
- font-size: 9pt;
- border: 1px ridge #999999;
- background-color: #FFFFFF;
- cursor:pointer;
- }
- TABLE {
- FONT: 9pt 宋体,Verdana,Arial
- }
- -->
- </style>
- <link href="E:ASPXDotNetTextBox2WebSite/system_dntb/skin/xp/toolbar.css" rel="stylesheet"
- type="text/css" />
- <link href="E:ASPXDotNetTextBox2WebSite/system_dntb/skin/xp/toolbar.css" rel="stylesheet"
- type="text/css" />
- </head>
- <body>
- <table align=center width="555">
- <tr>
- <td valign="top">
- <fieldset>
- <legend>演示说明</legend> 本例子演示DotNetTextBox控件提交内容到数据库并读取显示的应用实例,需要注意的是,提交到数据库的内容必须使用Server.HtmlEncode()进行HTML编码,否则如果内容里有非法字符的时候会导致插入数据库失败,另外在读取数据库内容的时候,必须使用Server.HtmlDecode()解码显示(本例子使用的ACCESS数据库名为:demo_database.mdb)!</fieldset>
- </td>
- </tr>
- </table>
- <br />
- <table width="100%" border="0" cellspacing="0" cellpadding="0">
- <tr>
- <td align="center"><form id="Form1" runat="server">
- <div align="center">
- <DNTB:WebEditor id="WebEditor1" Skin="skin/xp/" runat="server"></DNTB:WebEditor> </div>
- <p align="center">
- <asp:Button id="Button1" OnClick="Button1_OnClick" runat="server" Text="提交内容"></asp:Button>
- <asp:Button id="Button2" OnClick="Button2_OnClick" runat="server" Text="清空内容"></asp:Button>
- </p>
- </form></td>
- </tr>
- </table>
- <asp:label runat="server" ID="label1"></asp:label>
- </body>
- </html>