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"); } } 其他的就不用做了,这个就完成了将留言信息插入到数据库。 祝你好运!

  • 相关阅读:
    Centos 7 开放查看端口 防火墙关闭打开
    idea将项目导出为war包
    webstorm 注册服务器
    centos 6.4系统双网卡绑定配置详解
    centos所有版本镜像下载地址
    浅谈Nginx负载均衡与F5的区别
    勒索病毒应急响应计划
    Python网络编程常用代码
    Flask debug 模式 PIN 码生成机制安全性研究笔记
    Pythonic定义
  • 原文地址:https://www.cnblogs.com/wancy86/p/2254183.html
Copyright © 2011-2022 走看看