我想用這種方法消息錯誤「指定的轉換無效」
public List<gerant> getinfogerant()
{
List<gerant> gerer = new List<gerant>();
string sql_gerant = "select CIN,NOM,PRENOM,ADRESS_PERSONNEL,NUM_TEL,MAIL,MOBILE,CP_GERANT,VILLE_GERANT,DATE_CIN from GERANT";
connexion connect = new connexion();
OleDbConnection connection = connect.getconnexion();
connection.Open();
OleDbCommand cmd = new OleDbCommand(sql_gerant, connection);
OleDbDataReader reader = cmd.ExecuteReader();
while(reader.Read())
{
gerer.Add(new gerant(reader.GetInt64(0),
reader.GetString(1),
reader.GetString(2),
reader.GetString(3),
reader.GetDouble(4),
reader.GetString(5),
reader.GetDouble(6),
reader.GetInt32(7),
reader.GetString(8),
reader.GetDateTime(9))
);
}
connection.Close();
return gerer;
}
擺脫數據庫訪問信息在我的數據庫訪問我定義字段cin
爲長整型和格式化的「00000000」
但我在reader.GetInt64(0)
得到一個錯誤:
指定的轉換是無效
我該如何解決?
你是什麼意思格式化「0000000」?如果這是該語句的結果,則CIN是一個字符串。 – nabuchodonossor
CIN字段可以爲空嗎? – adrianbanks
你確定你在'reader.GetInt64(0)'中得到異常,而不是在整個'gerant'構造函數中? –