//获取DataSet
public DataSet SelectSqlSrvRows(string connection,string query)
{
SqlConnection conn = new SqlConnection(connection);
SqlDataAdapter adapter = new SqlDataAdapter();
adapter.SelectCommand = new SqlCommand(query, conn);
adapter.Fill(dataset);
return dataset;
}
//绑定Dropdoenlist
public void Dropdoenlist_DataBind
{
DataSet dataSet=SelectSqlSrvRows("connection to database string","select date,time from table");
foreach(DataRow row in dataSet.Tables[0].Rows)
{
dropdoenlist.Items.Add(row["date"].ToString()+" "+row["time"].ToString());
}
}
直接在查詢數據庫的時候組合成一個新的字段:
SELECT DATE + ' ' + TIME AS DATETIME FROM TABLENAME
[此贴子已经被作者于2007-7-10 9:39:55编辑过]