zoukankan      html  css  js  c++  java
  • asp.net留言板简单入门

    程序开始前的准备工作: 第一步,创建web.config中的连接字符串,后面读取它。 第二步,创建数据库,demo,用于存储留言数据。 use demo; create table msgboard( nickName nvarchar(20), email nvarchar(30), ipAddr nchar(20), msgTime date, msgTitle nchar(50), msgContent nchar(100) ); 第三步,创建主页面default.aspx 的内容如下: <%@ Page EnableViewStateMac="false" Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

    留言板

    <%--

    --%>豆腐技术站亲情奉献 <%--

    --%>
    您的呢称:
    您的联系Email:
    您的发言主题:
    您的留言内容
    察看所有留言

    第四步,doLiuyan.aspx页面的后台代码 using System; using System.Collections.Generic; using System.ComponentModel; using System.Collections; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Data; using System.Data.Sql; using System.Data.SqlClient; using System.Configuration; public partial class doLiuyan : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { SqlConnection Conn; //Hashtable Cfg; //Cfg = Context.GetConfig("appsettings"); string connstr = ConfigurationManager.AppSettings[0].ToString(); Conn = new SqlConnection(connstr); string strSQL = ""; string strNickName = ""; string strMail = ""; string strTitle = ""; string strContent = ""; string strIPAddr = ""; strNickName = Request.Form["txtName"].Replace("'", "''").ToString(); strMail = Request.Form["txtMail"].Replace("'", "''").ToString(); strTitle = Request.Form["txtTitle"].Replace("'", "''").ToString(); strContent = Request.Form["txtContent"].Replace("'", "''").ToString(); strIPAddr = Request.ServerVariables["REMOTE_ADDR"].ToString();//用户IP地址 strSQL = "insert into msgBoard(nickname,email,ipAddr,msgTime,msgTitle,msgContent)values("; strSQL = strSQL + "'" + strNickName + "','" + strMail + "','" + strIPAddr + "',getdate(),'" + strTitle + "','" + strContent + "')"; Response.Write(strSQL); //Conn.Open(); SqlCommand Cmd; Cmd = new SqlCommand(strSQL, Conn); Cmd.Connection.Open(); Cmd.ExecuteNonQuery(); Cmd.Connection.Close(); Response.Redirect("showmsg.aspx"); } } 其他的就不用做了,这个就完成了将留言信息插入到数据库。 祝你好运!

  • 相关阅读:
    原码、反码、补码详解
    进制转换
    目录
    Window【目录】
    排序算法——冒泡排序
    算法的时间复杂度与空间复杂度
    排序算法
    递归—八皇后问题
    递归—迷宫问题
    递归
  • 原文地址:https://www.cnblogs.com/wancy86/p/2254183.html
Copyright © 2011-2022 走看看