今天主要做的事,有关数据库的读取,排序,显示的问题。
代码如下:
SqlConnection mycon = GetConnection();
mycon.Open();
string sqlStr = "select _Author,_Title,_PubTime ,_Description,_Rank,_Catagory from _TableDoc order by _Rank DESC";
SqlCommand mycomd = new SqlCommand(sqlStr, mycon);
SqlDataReader sdr = mycomd.ExecuteReader();
while (sdr.Read())
{
downloadrank temp = new downloadrank();
temp.Author = sdr[0].ToString();
temp.Title = sdr[1].ToString();
temp.PubTime = sdr[2].ToString();
temp.Description = sdr[3].ToString();
temp.Rank = Convert.ToInt32(sdr[4].ToString());
temp.Catagory=sdr[5].ToString();
DownloadRank.Add(temp);
}
sdr.Close();
mycon.Close();
其中:
public SqlConnection GetConnection()
{ string sqlstr = "Server=(local);User id=sa;Pwd=10061177;DataBase=BigHouse"; SqlConnection con = new SqlConnection(sqlstr); return con; }