{ string connectionString = "Data Source=.;
Initial Catalog=HSDB;
Integrated Security=SSPI;";
SqlConnection conn = new SqlConnection(connectionString);
DataSet ds = new DataSet();
Try
{
if (conn.State == ConnectionState.Closed)
{ conn.Open(); }
SqlCommand cmd = new SqlCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = "select MaLop, TenLop from Lop";
cmd.Connection = conn;
using(SqlDataAdapter adapter = new SqlDataAdapter(cmd))
{ adapter.Fill(ds, "Lop"); }
this.ddlLop.DataSource = ds;
this.ddlLop.DataMember = "Lop";
this.ddlLop.DataTextField = "TenLop";
this.ddlLop.DataValueField = "MaLop";
this.ddlLop.DataBind();
return true;
}
catch { return false; }
finally { conn.Close(); }
}
» Tin mới nhất:
» Các tin khác: