wpf in c# returning error "not all code paths return a value" on GetProductRecords() -
this question has answer here:
- not code paths return value 5 answers
public class productrecord { private int _code; private string _name; private int _quantity; private string _size; private string _unit; private datetime _dateordered; private string _manufacturer;
public int code { { return _code; } set { _code = value; } } public string name { { return _name; } set { _name = value; } } public int quantity { { return _quantity; } set { _quantity = value; } } public string size { { return _size; } set { _size = value; } } public string unit { { return _unit; } set { _unit = value; } } public datetime dateordered { { return _dateordered; } set { _dateordered = value; } } public string manufacturer { { return _manufacturer; } set { _manufacturer = value; } } public static list<productrecord> getproductrecords() { list<productrecord> lstrecords = new list<productrecord>(); string strsql = "select * producttable"; oledbconnection cn = new oledbconnection(productcore.connectionstring); oledbcommand cmd = cn.createcommand(); cmd.commandtext = strsql; cn.open(); oledbdatareader reader = cmd.executereader(); while (reader.read()) { productrecord record = new productrecord(); record.code = convert.toint32(reader["code"]); record.name = reader["name"].tostring(); record.quantity = convert.toint32(reader["quantity"]); record.size = reader["size"].tostring(); record.unit = reader["unit"].tostring(); record.dateordered = convert.todatetime(reader["dateordered"]); record.manufacturer = reader["manufacturer"].tostring(); lstrecords.add(record); } cn.close(); }
that's because of lack of "return" keyword. declared method return object of type list, created instance of list in method body, , populated in loop. didn't return anywhere :) add
return lstrecords;
at end of method.
Comments
Post a Comment