利用c#制作的留言板.doc_第1页
利用c#制作的留言板.doc_第2页
利用c#制作的留言板.doc_第3页
利用c#制作的留言板.doc_第4页
利用c#制作的留言板.doc_第5页
已阅读5页,还剩3页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

如何让一个函数返回多个值(C#)有两种方法:1.使用指针变量声明函数(或者使用数组变量)2.使用传出参数第一种方法:函数返回的是一个指针地址(数组地址),这个内存地址有多个变量寄存在里面。这个方法我不太会用,传地址传值我常常搞的淅沥糊涂。第二种方法:我用例子说明。首先声名一个函数,定义如下public bool CheckUser(string UserName, out string PassWord, Out int State) if ( UserName = 123 ) PassWord = 456; State = 0; else PassWord = ; State = 1; return false;应用方法如下:string PassWord = ;int State = 0;string UserName = abc;bool falg = CheckUser(UserName,out PassWord, out State);这个就可以得到函数CheckUser返回的三个值falg 、PassWord、State在使用out型参数的时候必须事先声明,否则无法使用,可以看作输出参数的初始化。利用c#制作简单的留言板(1)来源:互联网时间: 2006-04-11 留言板分三个模块:列出留言列表、显示详细内容、发表留言notepage.csnamespace notpageusing System;using System.Data.SQL ;using System.Data ;using System.Collections ;/ / Summary description for notepage./ public class notepage/私有变量private int n_intID ; /ID编号private string n_strTitle ; /主题private string n_strAuthor ; /留言人private string n_strContent ; /留言内容private DateTime n_dateTime ; /留言时间/属性public int IDgetreturn n_intID ;set n_intID = value;public string Title getreturn n_strTitle ;setn_strTitle = value;public string Authorgetreturn n_strAuthor ;setn_strAuthor = value ;public string Contentgetreturn n_strContent ;setn_strContent = value ;public DateTime adddategetreturn n_dateTime;setn_dateTime = value;/构造函数public notepage()/ TODO: Add Constructor Logic here/this.n_intID = 0 ;this.n_strTitle = ;this.n_strAuthor = ;this.n_strContent = ;this.n_dateTime = System.DateTime.Now;/ / / 取得留言的内容/ / / public notepage GetTopic(int a_intID)/ TODO: Add Constructor Logic here/读取数据库myconn myConn = new myconn();SQLCommand myCommand = new SQLCommand() ;myCommand.ActiveConnection = myConn ;myCommand.CommandText = n_GetTopicInfo ; /调用存储过程myCommand.CommandType = CommandType.StoredProcedure ;myCommand.Parameters.Add(new SQLParameter(a_intTopicID , SQLDataType.Int) ;myCommand.Parametersa_intTopicID.Value = a_intID ;notepage objNp = new notepage();try myConn.Open() ;SQLDataReader myReader ;myCommand.Execute(out myReader) ;if (myReader.Read()objNp.ID = (int)myReaderID ;objNp.Title = (string)myReaderTitle ;objNp.Author = (string)myReaderAuthor ;objNp.Content = (string)myReaderContent;objNp.adddate = (DateTime)myReaderadddate;/清场myReader.Close();myConn.Close() ;catch(Exception e)throw(new Exception(取贴子失败: + e.ToString() ;return objNp;/ / / 目的:将留言的内容入库/ / 利用构造函数来传递信息/ / / public bool AddTopic(notepage n_Topic)/ TODO: Add Constructor Logic here/读取数据库myconn myConn = new myconn();SQLCommand myCommand = new SQLCommand() ;myCommand.ActiveConnection = myConn ;myCommand.CommandText = n_addTopic ; /调用存储过程myCommand.CommandType = CommandType.StoredProcedure ;myCommand.Parameters.Add(new SQLParameter(a_strTitle , SQLDataType.VarChar,100) ;myCommand.Parametersa_strTitle.Value = n_Topic.Title ;myCommand.Parameters.Add(new SQLParameter(a_strAuthor , SQLDataType.VarChar,50) ;myCommand.Parametersa_strAuthor.Value = n_Topic.Author ;myCommand.Parameters.Add(new SQLParameter(a_strContent , SQLDataType.VarChar,2000) ;myCommand.Parametersa_strContent.Value = n_Topic.Content ;try myConn.Open() ;myCommand.ExecuteNonQuery() ;/清场myConn.Close() ;catch(Exception e)throw(new Exception(取贴子失败: + e.ToString() ;return true;/ / 取的贴子列表/ / / 返回一个Topic数组/ public ArrayList GetTopicList()/定义一个forum数组做为返回值ArrayList arrForumList =new ArrayList() ;/从数据库中读取留言列表myconn myConn = new myconn();SQLCommand myCommand = new SQLCommand() ;myCommand.ActiveConnection = myConn ;myCommand.CommandText = n_GetTopicList ; /调用存储过程myCommand.CommandType = CommandType.StoredProcedure ;trymyConn.Open() ;SQLDataReader myReader ;myCommand.Execute(out myReader) ;for (int i = 0 ; myReader.Read() ; i+)notepage objItem = new notepage() ;objItem.ID = myReaderID.ToString().ToInt32() ;objItem.Title = myReaderTitle.ToString() ;objItem.Author = myReaderAuthor.ToString() ;objItem.adddate = myReaderadddate.ToString().ToDateTime(); objItem

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论