分享
 
 
 

更新、插入数据库所使用的UPDATE()

王朝other·作者佚名  2006-01-08
窄屏简体版  字體: |||超大  

<%@ 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>

这里更多的文件

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有