c# - How to return column values from two different tables? -
i'm trying recieve data database table , sql query selects column table return aswell
while (dr.read()) { inlagg comentsar = new inlagg { names = (int)dr["name"], dates = (datetime)dr["date"] //get column value other table not inlagg table here pobbisble? }; //this gets column value other table dont know how return string test = (string)dr["test"]; comen.add(comentsar); } return comen;
how can return result includes columns both columns different tables? side note: have column dont need recieve here, altough column int , i'm trying recieve string, there way cast column string? or input highly appreciated, thanks!
edit: "solved" creating new class values wanted included columnvalues different tables
inside of reader, missing following:
if(reader["column"] != dbnull.value) model.name = reader["column"].tostring();
your query sql should correctly join multiple tables, in returned result set have column name return by. call reader["..."]
access value said column.
as notice model
class calls name of property.
the model important represents data, access through reader add property.
that because column null
, can't cast tostring()
why error occurs. attempt do:
int? example = reader["column"] int?;
Comments
Post a Comment