|
利用c#制作简单的留言板(1) (2) myCommand.CommandType = CommandType.StoredProcedure ; myCommand.Parameters.Add(new SQLParameter("@a_intTopicID" , SQLDataType.Int)) ; myCommand.Parameters["@a_intTopicID"].Value = a_intID ;
notepage objNp = new notepage(); try {
myConn.Open() ; SQLDataReader myReader ; myCommand.Execute(out myReader) ; if (myReader.Read()) { objNp.ID = (int)myReader["ID"] ; objNp.Title = (string)myReader["Title"] ; objNp.Author = (string)myReader["Author"] ; objNp.Content = (string)myReader["Content"]; objNp.adddate = (DateTime)myReader["adddate"]; }
//清场 myReader.Close(); myConn.Close() ;
} catch(Exception e) { throw(new Exception("取贴子失败:" + e.ToString())) ; } return objNp;
}
/// <summary> /// /// 目的:将留言的内容入库 /// /// 利用构造函数来传递信息 /// /// </summary> /// <param name="n_Topic"> </param> 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.Parameters["@a_strTitle"].Value = n_Topic.Title ;
myCommand.Parameters.Add(new SQLParameter("@a_strAuthor" , SQLDataType.VarChar,50)) ; myCommand.Parameters["@a_strAuthor"].Value = n_Topic.Author ;
myCommand.Parameters.Add(new SQLParameter("@a_strContent" , SQLDataType.VarChar,2000)) ; myCommand.Parameters["@a_strContent"].Value = n_Topic.Content ;
try {
myConn.Open() ; myCommand.ExecuteNonQuery() ;
//清场
myConn.Close() ;
}
|