RDV+DIAL chat illimit� dans ta r�g!
no save
Assistance
Achat
News

Forum | programmation
Ouvrir mon DataReader???
SonOfGod7, le ven. 03 juil. 2009 à 23:30:09
Bonjour,
Salut,
Voila j'ai un problème avec mon script,
Voici une methode de ma classe AccesData: cette methode me retourne un datareader.

public System.Data.Common.DbDataReader ExecuteReader(String CommandText, ref System.Data.Common.DbConnection conn)
{
System.Data.Common.DbCommand oDbCommand;
System.Data.Common.DbDataReader oDbDataReader;
try
{
conn.Open();
oDbCommand = this.CreateCommand(CommandText, conn, System.Data.CommandType.Text);

oDbDataReader = oDbCommand.ExecuteReader(System.Data.CommandBehavior.CloseConnection);


}
catch (Exception ex)
{
throw ex;
}
finally
{
conn.Close();
}

return oDbDataReader;
}
Voici le code et voici mon Main

static void Main(string[] args)
{
AccesData obj;
obj = AccesData.GetInstance();
System.Data.Common.DbConnection conn;
conn = obj.CreateConnection("System.Data.SqlClient", "initial catalog=data; data source=.;integrated security=true;");
System.Data.Common.DbDataReader Da ;
Da = obj.ExecuteReader("select * from data",ref conn);
conn.Open();

Console.Write("Le nombre de ligne changer est {0}", Da.Read());
while (Da.Read())
{
Console.WriteLine("de numero {0} et de nom {1}", Da["id"], Da["name"]);
}
conn.Close();
Console.ReadLine();
}
voici les detail de mon erreur

L'exception System.InvalidOperationException n'a pas été gérée
Message="Tentative d'appel de Read non valide lorsque le lecteur est fermé."
Source="System.Data"
StackTrace:
à System.Data.SqlClient.SqlDataReader.ReadInternal(Boolean setTimeout)
à System.Data.SqlClient.SqlDataReader.Read()
à test.Program.Main(String[] args) dans D:\Boss\Script\projet été\C# - 2SF\test1\test1\Program.cs:ligne 173
à System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
à System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
à Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
à System.Threading.ThreadHelper.ThreadStart_Context(Object state)
à System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
à System.Threading.ThreadHelper.ThreadStart()
InnerException:
c'est quoi le Lecteur es ce le dataset .
Si oui comment l'ouvrir , je n'ai rien trouvé sur le netConfiguration: Windows XP
Safari 530.5


kuchi007
04 juil.
Suivant
REPONSES
kuchi007
04 juil.
SonOfGod7
11 juil.
kuchi007
12 juil.
Version Web
Réalisé par RedShift
no save