Skip to content
Advertisement

Tag: datareader

How to fill Dataset with multiple tables?

I’m trying to fill DataSet which contains 2 tables with one to many relationship. I’m using DataReader to achieve this : But I’ve got only one table filled up. How do I achieve my goal – fill both tables? I would like to use DataReader instead DataAdapter, if it possible. Answer If you are issuing a single command with several

DataReader.GetString() via columnname

Dictionary Fields = new Dictionary(); for (int i = 0; i < reader.FieldCount; i++) { Fields.Add(reader.GetName(i), i); } this._MyField1 = reader.GetString(Fields[“field1”]); this._Myfield2 = reader.GetInt16(Fields[“field2”]); doing this makes me want to cry but i can’t seem to figure out how to use the type specfic retrieval methods by column name other than this way. please tell me there is a better

Advertisement