It doesn't look like you are attempting to return any rows but are instead inserting rows. Is this true? Would you be willing to share the value of airportDefaultCurrencyCreate and if it is a call to a stored procedure or function the code of that as well
please?
GorillaMann
Member
117 Points
332 Posts
reader.Read is always false
Nov 09, 2012 08:27 AM|LINK
how come reader.Read is always false after a succesful insert?
using (var command = new SqlCommand(airportDefaultCurrencyCreate, connectionProvider.Connection))
{
command.CommandType = CommandType.Text;
command.Parameters.AddWithValue("IataAirportCode", airportDefaultCurrency.IataAirportCode);
using (SqlDataReader reader = command.ExecuteReader())
{
if (reader.Read())
return Load(reader);
else
throw new CreateFailedException(airportDefaultCurrency);
}
}
santosh.jagd...
Star
7625 Points
1454 Posts
Re: reader.Read is always false
Nov 09, 2012 08:39 AM|LINK
if you are trying to retrun inserted value, then use ExecuteScalar instead ExecuteReader.
MCP
UselessChimp
Member
210 Points
110 Posts
Re: reader.Read is always false
Nov 10, 2012 08:16 PM|LINK
It doesn't look like you are attempting to return any rows but are instead inserting rows. Is this true? Would you be willing to share the value of airportDefaultCurrencyCreate and if it is a call to a stored procedure or function the code of that as well please?
anil.india
Contributor
2613 Points
453 Posts
Re: reader.Read is always false
Nov 11, 2012 05:37 PM|LINK
instead of ExecuteReader() you need to use ExecuteNoneQuery() . This returns the no of records affected.
codepattern.net/blog ||@AnilAwadh
GorillaMann
Member
117 Points
332 Posts
Re: reader.Read is always false
Nov 12, 2012 11:20 AM|LINK
I'm trying get the object back I create ie:
private static AirportDefaultCurrency Load(SqlDataReader reader)
{
return new AirportDefaultCurrency((string) reader["IataAirportCode"], (string) reader["AirportFullName"]
);
}