Which code is better to use

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • hime
    New Member
    • Oct 2006
    • 13

    Which code is better to use

    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


    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();
  • kenobewan
    Recognized Expert Specialist
    • Dec 2006
    • 4871

    #2
    Define better... Have you tested them, does either of them work?

    Comment

    • hime
      New Member
      • Oct 2006
      • 13

      #3
      Originally posted by kenobewan
      Define better... Have you tested them, does either of them work?
      Hi;

      yes both codes does work but i need to know which one is more efficient for the program. i mean in which case should we use dataset and dataadapter and in which should we use datareader and command in other words i want to know exactly when to use each one of them

      thanx

      Comment

      • kenobewan
        Recognized Expert Specialist
        • Dec 2006
        • 4871

        #4
        Here is an article that may help:
        DataSet Vs. DataReader

        Comment

        Working...