62,074
社区成员
发帖
与我相关
我的任务
分享
OleDbConnection conn = null;
OleDbDataReader myReader = null;
List<KS_Article> list = null;
try
{
string sql = "select a.id,a.tid,c.Folder,a.title,a.articlecontent,a.inputer from KS_Article as a,KS_Class as c where a.tid=c.id order by a.id";
conn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=|DataDirectory|1.mdb");
OleDbCommand cmd = new OleDbCommand(sql, conn);
if (conn.State != ConnectionState.Open)
conn.Open();
myReader = cmd.ExecuteReader();
list = new List<KS_Article>();
while (myReader.Read())
{
KS_Article temp = new KS_Article();
temp.id = (int)myReader["id"];
//string tid = (string)myReader["tid"];
temp.tid = (string)myReader["tid"];
temp.folder = (string)myReader["Folder"];
temp.title = (string)myReader["title"];
temp.articlecontent = (string)myReader["articlecontent"];
temp.inputer = (string)myReader["inputer"];
temp.uphtml = getUphtmlById(temp.id, temp.tid);
list.Add(temp);
}
return list;
}
catch (System.Data.OleDb.OleDbException e)
{
throw new Exception(e.Message);
}
finally
{
myReader.Close();
conn.Close();
}
for (int i = 0; i < list.Count; i++)
{
uplist = list.Take(i + 1).ToList<KS_Article>();
downlist = list.Skip(i + 1).ToList<KS_Article>();
List<KS_Article> uphtml = (from p in uplist where p.tid == list[i].tid where p.id < list[i].id orderby p.id descending select p).Take(1).ToList<KS_Article>();
List<KS_Article> downhtml = (from p in downlist where p.tid == list[i].tid where p.id > list[i].id orderby p.id ascending select p).Take(1).ToList<KS_Article>();
if (uphtml.Count != 0)
list[i].uphtml = uphtml[0].id.ToString() + ".html";
else
list[i].uphtml = "无";
if (downhtml.Count != 0)
list[i].downhtml = downhtml[0].id.ToString() + ".html";
else
list[i].downhtml = "无";
}
private string getUphtmlById(int id,string tid)
{
string sql = "select top 1 id as uphtml from KS_Article where [id] < " + id + " and tid = '" + tid + "' order by id";
//OleDbConnection conn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=|DataDirectory|1.mdb");
OleDbCommand cmd = new OleDbCommand(sql, conn);
OleDbDataReader myReader = null;
try
{
myReader = cmd.ExecuteReader();
if (myReader.Read())
{
if (myReader["uphtml"].ToString() == "")
return "-1";
return myReader["uphtml"].ToString();
}
return "-1";
}
catch (System.Data.OleDb.OleDbException e)
{
throw new Exception(e.Message);
}
finally
{
myReader.Close();
}
}
for (int i = 0; i < list.Count; i++)
{
var m = (from p in list where p.tid == list[i].tid where p.id < list[i].id select p.id).Skip(1).Take(1);
list[i].uphtml = "m转换";
}