这里参考了Erist.Protal里的代码
代码如下:
/// <summary>
/// 增加新的文章
/// </summary>
/// <param name="ArticleTitle"></param>
/// <param name="Author"></param>
/// <param name="ArticleFrom"></param>
/// <param name="Creator"></param>
/// <param name="ModifyBy"></param>
/// <param name="Content"></param>
/// <param name="ChannelID"></param>
/// <param name="IsOnTop"></param>
/// <param name="IsCommend"></param>
/// <param name="IsCheck"></param>
/// <param name="Keyword"></param>
/// <param name="ArticleIntroduction"></param>
/// <returns>新增加文章的ID</returns>
public int AddArticle(string ArticleTitle,
string Author,
string ArticleFrom,
int Creator,
int ModifyBy,
string Content,
int ChannelID,
bool IsOnTop,
bool IsCommend,
bool IsCheck,
string Keyword,
string ArticleIntroduction)
{
int ArticleID =-1;
//格式化HTML标记
ArticleTitle=System.Web.HttpUtility.HtmlEncode(ArticleTitle);
Author=System.Web.HttpUtility.HtmlEncode(Author);
Keyword=System.Web.HttpUtility.HtmlEncode(Keyword);
OleDbConnection OleCon=new OleDbConnection(Globals.ConnectString);
OleDbCommand OleCmd=new OleDbCommand();
OleCmd.CommandType=System.Data.CommandType.StoredProcedure;
OleCmd.Connection=OleCon;
OleCmd.CommandText="AddArticle";
//取得下一个ID号
ArticleID= Erist.Common.Data.DataProvider.GetAutoID("ArticleID","Article",Globals.ConnectString);
OleCmd.Parameters.Add("ArticleID",ArticleID);
OleCmd.Parameters.Add("ArticleTitle",ArticleTitle);
OleCmd.Parameters.Add("Author",Author);
OleCmd.Parameters.Add("ArticleFrom",ArticleFrom);
OleCmd.Parameters.Add("Creator",Creator);
OleCmd.Parameters.Add("ModifyBy",ModifyBy);
OleCmd.Parameters.Add("Content",Content);
OleCmd.Parameters.Add("ChannelID",ChannelID);
OleCmd.Parameters.Add("IsOnTop",IsOnTop);
OleCmd.Parameters.Add("IsCommend",IsCommend);
OleCmd.Parameters.Add("IsCheck",IsCheck);
OleCmd.Parameters.Add("Keyword",Keyword);
//2004-2-2将文章增加简介属性 姜勇
OleCmd.Parameters.Add("ArticleIntroduction",ArticleIntroduction);
//执行
Erist.Common.Data.DataProvider.ExecNonQueryOle(OleCmd);
return ArticleID;
}
注意看背景色为橙色的地方调用了Erist.Common.Data.DataProvider.GetAutoID()
下面是此方法的代码
代码如下:
/**//// <summary>
/// 取得数据集
/// </summary>
/// <param name="SqlCmd">执行命令的SqlCommand</param>
/// <returns>返回取得的数据集</returns>
public static DataSet GetDataSetOle(OleDbCommand OleCmd )
{
OleDbDataAdapter t_DataAdapter ;
DataSet t_DataSet=new DataSet();
try
{
if (OleCmd.Connection.State != ConnectionState.Open) OleCmd.Connection.Open();