首 页 | 新 闻 | 技术中心 | 第二书店 | 《程序员》 | 《开发高手》 | 社 区 | 黄 页 | 人 才
移 动专 题SUNIBM微 软微 创精 华Donews人 邮
我的技术中心 
我的分类 我的文档
全部文章 发表文章
专栏管理 使用说明



 RSS 订阅 
最新文档列表
Windows/.NET
.NET  (rss)    
Visual C++  (rss)    
Delphi  (rss)    
Visual Basic  (rss)    
ASP  (rss)    
JavaScript  (rss)    
Java/Linux
Java  (rss)    
Perl  (rss)    
综合
其他开发语言  (rss)    
文件格式  (rss)    
企业开发
游戏开发  (rss)    
网站制作技术  (rss)    
数据库
数据库开发  (rss)    
软件工程
其他  (rss)    

积极原创作者 
btbtd (83)
coofucoo (107)
longrujun (64)
cyz1980 (101)
ssll2826 (10)
EmilMatthew (73)
goodboy1881 (15)
superlmj (12)
feng19821209 (9)
yjz0065 (115)
CSDN - 文档中心 - .NET 阅读:3992   评论: 4    参与评论
标题   更新、插入数据库所使用的UPDATE()     选择自 tingningpower 的 Blog
关键字   更新、插入、OLEDB ,data,access,C#
出处  

<%@ Page Language="C#" EnableSessionState="False" %>
<%@ Import Namespace="System" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.OleDb" %>
<%@ Import Namespace="System.Text" %>
<%@ Import Namespace="System.IO" %>

<html>
<head>
<title>谢谢你的留意!在听宁信息!^_^</title>
<script language="C#" runat="server" codepage="936">
 
  void Page_Load(Object Src, EventArgs E)
  {
     //Check id the page is loaded for the first time
     if (!Page.IsPostBack) {
       //Get the Parameters from the Query string and store it
       string name = Request.Params["name"] ;
       string email = Request.Params["email"] ;
       string subject = Request.Params["subject"] ;
       string ip = Request.Params["ip"] ;
       string date = Request.Params["date" ];
       string message = Request.Params["message"] ;
       bool newmess =true ;
       string previd ="1";
       //Check of the 'newpost' paramater is 'no'
       //indicating that its a reply to a previous post
       if(Request.Params["newpost"].Equals("no"))
       {
          newmess =false ;
          //Since its a reply, we get the ID of the topic
          //to which this post is a reply
          previd = Request.Params["previd"] ;
       }
      
       if(newmess)
       {
          //Execute the code below to insert a new topic
          string
strConn=@"Provider=Microsoft.Jet.OleDb.4.0 ;Data Source=";
                 strConn+=Server.MapPath(".\\db\\board.mdb") ;
         
          OleDbConnection myConn = new OleDbConnection(strConn) ;
          //SQL query with Parameters
         string insertStr =" INSERT INTO newpost (name, email, subject, ip, dt, message) VALUES ";
           insertStr+="(@name, @email, @subject, @ip, @dt, @message)";
          //Create a new OleDbCommand
          OleDbCommand insertCommand = new OleDbCommand(insertStr, myConn);
          //Add a new Parameter
'@name' of the type 'VarChar'
          //and set its value
          insertCommand.Parameters.Add(new OleDbParameter("@name", OleDbType.VarChar));
          insertCommand.Parameters["@name"].Value = name;
    
          insertCommand.Parameters.Add(new OleDbParameter("@email", OleDbType.VarChar));
          insertCommand.Parameters["@email"].Value = email;

 insertCommand.Parameters.Add(new OleDbParameter("@subject", OleDbType.VarChar));
          insertCommand.Parameters["@subject"].Value = subject;

  insertCommand.Parameters.Add(new OleDbParameter("@ip", OleDbType.VarChar));
          insertCommand.Parameters["@ip"].Value = ip;

  insertCommand.Parameters.Add(new OleDbParameter("@dt", OleDbType.VarChar));
          insertCommand.Parameters["@dt"].Value = date;

         insertCommand.Parameters.Add(new OleDbParameter("@message", OleDbType.VarChar));
          //Give a call the the 'parsetext' method to parse the message
          insertCommand.Parameters["@message"].Value = parsetext(message);

          myConn.Open();
          //Execute Non Query to insert a new topic in the database
          insertCommand.ExecuteNonQuery();
          myConn.Close() ;
        }
        else
        {
           //Insert a reply to a previous topic
           string
strConn=@"Provider=Microsoft.Jet.OleDb.4.0 ;Data Source=";
                  strConn+=Server.MapPath(".\\db\\board.mdb") ;
           OleDbConnection myConn = new OleDbConnection(strConn);
           //SQL statement with Parameters
           string insertStr =" INSERT INTO reply (name, email, subject, ip, dt, ";
                  insertStr+="message, postid) VALUES ";
                 insertStr+="(@name, @email, @subject, @ip, @dt, @message, @postid)";
  //Create a new OleDbCommand
          OleDbCommand insertCommand = new OleDbCommand(insertStr, myConn);
   //Add a new Parameter and set its value
          insertCommand.Parameters.Add(new OleDbParameter("@name", OleDbType.VarChar));
          insertCommand.Parameters["@name"].Value = name;
          insertCommand.Parameters.Add(new OleDbParameter("@email", OleDbType.VarChar));
          insertCommand.Parameters["@email"].Value = email;
         insertCommand.Parameters.Add(new OleDbParameter("@subject", OleDbType.VarChar));
          insertCommand.Parameters["@subject"].Value = subject;
  insertCommand.Parameters.Add(new OleDbParameter("@ip", OleDbType.VarChar));
          insertCommand.Parameters["@ip"].Value = ip;
  insertCommand.Parameters.Add(new OleDbParameter("@dt", OleDbType.VarChar));
          insertCommand.Parameters["@dt"].Value = date;
       insertCommand.Parameters.Add(new OleDbParameter("@message", OleDbType.VarChar));
           //Give a call the the 'parsetext' method to parse the message
          insertCommand.Parameters["@message"].Value = parsetext(message);
         insertCommand.Parameters.Add(new OleDbParameter("@postid", OleDbType.Integer));
          insertCommand.Parameters["@postid"].Value = previd;
          myConn.Open();
  //Update the Database
          insertCommand.ExecuteNonQuery() ;
          myConn.Close();
          //SQL string to get the 'replies' column of the topic
  //to which this post is a reply
          string replyno = "SELECT replies FROM newpost WHERE postid ="+previd ;
          insertCommand.CommandText =replyno ;
          myConn.Open();
          OleDbDataReader reader =insertCommand.ExecuteReader() ;
          reader.Read();
  //Get the number of replies to this post
          int rep =reader.GetInt16(0) ;
          myConn.Close();
          rep++ ;
          //SQL statement to update the number of replies
  //of the topic to which this post is a reply
          string updtStr ="UPDATE newpost SET replies = "+rep
  +" WHERE (postid = "+previd+")" ;
          insertCommand.CommandText = updtStr;
          myConn.Open();
          //Execute the command
          insertCommand.ExecuteNonQuery();
          myConn.Close() ;
       }
       //Set the text of various textboxes to inform
       //the user of the text entered into the database
       NameLabel.Text = name;
       EmailLabel.Text= email ;
       SubjectLabel.Text=subject;    
       MessageLabel.Text=message ;   
    }
   else
    {
       errmess.Text="This Page Cannot be called directly.";
       errmess.Text+=" It has to be called from the Form posting page.<br>" ;
     }
  }
  //Class to parse the Message into HTML format
  public string parsetext(string text)
  {
  //Create a StringBuilder object from the string input
  //parameter
  StringBuilder sb = new StringBuilder(text) ;
  //Replace all double white spaces with a single white space
  //and &nbsp;
  sb.Replace("  "," &nbsp;");
  //Check if HTML tags are not allowed
 
     //Convert the brackets into HTML equivalents
     sb.Replace("<","&lt;") ;
     sb.Replace(">","&gt;") ;
     //Convert the double quote
     sb.Replace("\"","&quot;");

  //Create a StringReader from the processed string of
  //the StringBuilder
  StringReader sr = new StringReader(sb.ToString());
  StringWriter sw = new StringWriter();
  //Loop while next character exists
  while(sr.Peek()>-1)
  {
    //Read a line from the string and store it to a temp
    //variable
    string temp = sr.ReadLine();
    //write the string with the HTML break tag
    //Note here write method writes to a Internal StringBuilder
    //object created automatically
    sw.Write(temp+"<br>") ;
  }
  //Return the final processed text
  return sw.GetStringBuilder().ToString();
}

</script>
</head>
<body topmargin="0" leftmargin="0" rightmargin="0" marginwidth="0" marginheight="0">

<center>
<asp:label id="errmess" text="" style="color:#FF0000" runat="server" />
<h2 class="fodark"><b>谢谢谢!你在听宁信息城填广场留下你的笔迹!</b></h2>
<table align=center width="60%" border="0" cellspacing="2" cellpadding="1" >
<tr class="fohead"><td colspan="2">你留下以下的信息!谢谢!^_^</td></tr>
<tr class="folight">
<td>名名:</td> 
<td><asp:label id="NameLabel" text="" runat="server" /></td>
</tr>
<tr class="folight">
<td>E-Mail :</td> 
<td><asp:label id="EmailLabel" text="" runat="server" /></td>
</tr>
<tr class="folight">
<td>标题 :</td>
<td><asp:label id="SubjectLabel" text="" runat="server" /></td>
</tr>
<tr class="folight">
<td>信息内容:</td>
<td><asp:label id="MessageLabel" text="" runat="server" /></td>
</tr>
</table>

</center>
</body>
</html>

这里更多的文件


相关文章
对该文的评论
ufo_ufo ( 2004-03-19)
kao! 烂!
zellzhang ( 2003-07-27)
一点解释也没有,搞得我都懒得看了。。。
frankinlu ( 2003-04-29)
怎么把HTML语言也一块贴出来
runrunrun ( 2003-03-25)
这也叫文章?