只要求输出数据库中的第一列!!!
要是没代码 请不要发贴,谢谢!
刚写的航班查询,没写注释,自己看吧.
private void Page_Load(object sender, System.EventArgs e)
{
if(!this.IsPostBack)
{
this.GetFlightCityName();
}
}
void GetFlightCityName()
{
DAL.HB dal = new HBinfo.DAL.HB();
DataTable dt = dal.GetFlightCityNameByFlight();
for(int i=0;i<dt.Rows.Count;i++)
{
this.DropDownList1.Items.Add(dt.Rows[i]["DepartureCityName"].ToString());
}
}
//////////////
public class HB
{
const string SQL_CATE_SELECTFLIGHTCITYNAME = "select DepartureCityName from Flight";
/// <summary>
///
/// </summary>
/// <returns></returns>
public DataTable GetFlightCityNameByFlight()
{
DataTable dt = new DataTable();
SqlHelper.FillDataTable(SQL_CATE_SELECTFLIGHTCITYNAME,dt);
return dt;
}
}
///////////////
public class SqlHelper
{
static public readonly string ConnStr= "server=.;uid=sa;pwd=;database=HBInfo";
/// <summary>
///
/// </summary>
/// <param name="sql"></param>
/// <param name="dt"></param>
static public void FillDataTable(string sql, DataTable dt,params SqlParameter[]parms)
{
using(SqlConnection con = new SqlConnection(ConnStr))
{
SqlDataAdapter ada = new SqlDataAdapter(sql, con);
foreach(SqlParameter p in parms)
ada.SelectCommand.Parameters.Add(p);
ada.Fill(dt);
}
}
}