Hi I am writing this method but get an error that says "Specified cast is not valid. " in the "Books books = new Books((string)reader[0], (string)reader[1]," line. Anyone pls suggests me.
public List<Books> GetBooks()
{
List<Books> bookList = new List<Books>();
SqlConnection myConnection = new SqlConnection(connectionString);
SqlCommand myCommand = new SqlCommand("SPGetAllBooks", myConnection);
myConnection.Open();
SqlDataReader reader = myCommand.ExecuteReader();
while (reader.Read())
{
Books books = new Books((string)reader[0], (string)reader[1],
(string)reader[2], (string)reader[3], (int)reader[4]
,(double)reader[5], (int)reader[6], (int)reader[7]
,(string)reader

);
bookList.Add(books);
}
myConnection.Close();
reader.Close();
myCommand.Dispose();
if (bookList != null && bookList.Count > 0)
return bookList;
else return null;
}
The following is my constructor in Books class :
public Books(string bookID, string title, string authorFirstname
, string authorLastname, int edition, double price,
int discount, int amount, string category)