c# - How to populate list or array with values from access database -
i trying populate group of labels in c# windows form values in attribute (playername) in database have in access.
currently code have is:
oledbconnection connection = new oledbconnection(connection string here); oledbcommand command = new oledbcommand(); command.connection = connection; command.commandtext = "select playername [totalplayername] team = 1 , sportid = " + form1.idnumber;
i need list or array holds these values can use them populate labels, unaware of how this.
you need call executereader
obtain data reader , loop through rows of result set this:
list<string> result = new list<string>(); using (var reader = command.executereader()) { while (reader.read()) { result.add(reader.getstring(0)); } }
before this, don't forget open connection this:
connection.open();
Comments
Post a Comment