hello all,
i am programming a webform which include a dropdownlist bind to DB to show the entries in a certain column in a table the user can chose an item and insert or update the tables I have two codes one thet used a dataset and the other code i used datareader to bind the list to the needed items and am not sure which one is beter to use in the webform
i am programming a webform which include a dropdownlist bind to DB to show the entries in a certain column in a table the user can chose an item and insert or update the tables I have two codes one thet used a dataset and the other code i used datareader to bind the list to the needed items and am not sure which one is beter to use in the webform
Code:
MySqlDataAdapter depada = new MySqlDataAdapter("select * from dep1",con);
DataSet ds = new DataSet();
depada.Fill(ds);
lstdepa.DataSource = ds;
lstdepa.DataMember = ds.Tables[0].TableName;
lstdepa.DataTextField = "depname";
lstdepa.DataValueField = "depid";
lstdepa.DataBind();
Code:
MySqlCommand MySqlComm = new MySqlCommand("SELECT * FROM dep", con);
con.Open();
ddDR = MySqlComm.ExecuteReader(CommandBehavior.CloseConnection);
lstdepe.DataSource = ddDR;
lstdepe.DataTextField = "depname";
lstdepe.DataValueField = "depid";
lstdepe.DataBind();
con.Close();
Comment