and the error is:Code:using (SqlConnection con = new SqlConnection()) { con.ConnectionString = "Data Source=.\\SQLEXPRESS;Initial Catalog=AdventureWorks;Integrated Security=True"; using (SqlCommand cmd = con.CreateCommand()) { cmd.CommandType = CommandType.Text; cmd.CommandText = "select FirstName,LastName,ModifiedDate from Person.Contact order by Title;select * from HumanResources.Employee"; con.Open(); using (SqlDataReader reader = cmd.ExecuteReader()) { while (reader.Read()) { //Error triggered here Console.WriteLine(" {0} {1} - {2,18:D}", reader["FirstName"], reader[1], reader.GetDateTime(0)); } Console.WriteLine(Environment.NewLine); reader.NextResult(); Console.WriteLine("Employee Table Metadata"); for (int field = 0; field < reader.FieldCount; field++) { Console.WriteLine("Column Name : {0} Type : {1}", reader.GetName(field), reader.GetDataTypeName(field)); } } }
InvalidCastException was unhandled
Specified cast is not valid
also I tried
it still showing me same errorCode:Console.WriteLine(" {0} {1} - {2,18:D}", (string)reader["FirstName"].ToString(), (string)reader[1].ToString(), reader.GetDateTime(0));
Help me!




Reply With Quote