.NET开发

本类阅读TOP10

·NHibernate快速指南(翻译)
·vs.net 2005中文版下载地址收藏
·【小技巧】一个判断session是否过期的小技巧
·VB/ASP 调用 SQL Server 的存储过程
·?dos下编译.net程序找不到csc.exe文件
·通过Web Services上传和下载文件
·学习笔记(补)《.NET框架程序设计(修订版)》--目录
·VB.NET实现DirectDraw9 (2) 动画
·VB.NET实现DirectDraw9 (1) 托管的DDraw
·建站框架规范书之——文件命名

分类导航
VC语言Delphi
VB语言ASP
PerlJava
Script数据库
其他语言游戏开发
文件格式网站制作
软件工程.NET开发
Required_Field_OLEDB INSERT INTO .mdb data

作者:未知 来源:月光软件站 加入时间:2005-2-28 月光软件站

<%@ Import Namespace="System.Data" %>
<%@ Import namespace="System.Data.OleDb" %>

<html>
  <head>
    <title>Validating a Field</title>
  </head>
  <body>
    <form id="Form1" method="post" runat="server">
      <table id="Table1"
             style="Z-INDEX: 101; LEFT: 8px; POSITION: absolute; TOP: 8px"
             cellSpacing="0" cellPadding="0" width="300" border="0">
        <tr>
          <td style="WIDTH: 115px">
            <asp:Label id="Label1" runat="server">Category Name</asp:Label>
          </td>
          <td>
            <asp:TextBox id="txtCategoryName" runat="server" width="193" />
          </td>
        </tr>
        <tr>
          <td style="WIDTH: 115px">
            <asp:Label id="Label2" runat="server">Description</asp:Label>
          </td>
          <td>
            <asp:TextBox id="txtDescription" runat="server" width="193" />
          </td>
        </tr>
        <tr>
          <td style="WIDTH: 115px" colSpan="2">
            <asp:Button id="btnInsert" runat="server"
                 OnClick="btnInsert_Click" width="298" text="INSERT!" />
          </td>
        </tr>
      </table>
      <asp:RequiredFieldValidator id="rfvCategoryName" runat="server"
          style="Z-INDEX: 102; LEFT: 316px; POSITION: absolute; TOP: 14px"
          ErrorMessage="Please insert the new category name"
          ControlToValidate="txtCategoryName" />
    </form>
  </body>
</html>

<script language="c#" runat="server">
OleDbConnection objConnection;

private void Page_Load(object sender, System.EventArgs e)
{
  string strConnection = "Provider=Microsoft.Jet.OleDb.4.0;";
  strConnection += @"data source=\\genfs1\www11\etning\xml\Northwind.mdb";
}

private void btnInsert_Click(object sender, System.EventArgs e)
{
  if (Page.IsValid)
  {
    String strSQL = "INSERT INTO Categories (CategoryName, Description) VALUES (?, ?)";

    OleDbCommand dbComm = new OleDbCommand(strSQL, objConnection);
    dbComm.Parameters.Add("CategoryName", OleDbType.VarChar, 32, "CategoryName");
    dbComm.Parameters.Add("Description", OleDbType.VarChar, 128, "Description");

    dbComm.Parameters["CategoryName"].Value = txtCategoryName.Text;
    dbComm.Parameters["Description"].Value = txtDescription.Text;

    try
    {
      objConnection.Open();
      dbComm.ExecuteNonQuery();
    }
    catch (Exception ex)
    {
      Response.Write(ex.Message);
      Response.End();
    }
    finally
    {
      if (objConnection.State == ConnectionState.Open);
        objConnection.Close();
    }

    Response.Write("A new record has been added");
    Response.End();
  }
}
</script>




相关文章

相关软件