locked
I have a problem while filling my dataset using datareader. RRS feed

  • Question

  • User-388731848 posted

    I have a Access database. I wantto connect it and fill dataset with dataadapter. However i throws an exception that says  "System.InvalidOperationException was caught" And in detail it says that "When connection assigned to the command  is in a local operation,  ExecuteReader, requires that command must have a operation. Command's transaction is not started."

    Here is my code:

    string CmdText = "SELECT Kimlik, UNVANKODU, UNVANSIRA, IKINCIGOREV, IGONAYTARSAY, AKUNVAN, ADI, SOYADI, KIZSOYADI, SICIL, KADROKURUM, KADKURKOD, GECICIGOREV, GECICIGOREVKODU, ONAYMAKTARSAY, AYRILTAR, MEMURBASLAYIS, KURUMBASTAR, TCNO, ESNO, MEDENIHALI, CINSIYETI, DOGUMYERI, DOGUMTARIHI, BABAADI, ANNEADI, KANGURUBU, KROSOSHASTA, OGDURUMU, EVTEL, CEPTEL, EVADRESI, GELDIGIKURUM, GECGORYER, PARTTIMELISTESI, PARTTIMEYERI, KURSEGITIM, EMAIL, SENDIKA, Alan39 FROM CALISANLAR " +

    "WHERE (ADI LIKE '*" + fADI + "*') AND (SOYADI LIKE '*" + fSOYADI + "*')";

    Baglanti = new Baglan();

    try

    {

    Baglanti.Ac();

     

    DataTable dt= new DataTable(); OleDbDataAdapter da = new OleDbDataAdapter(CmdText, Baglanti.Connection);

    da.Fill(dt);

    return "başarılı";

    fSONUC = dt;

    }

    catch

    {

    return "başarısız";

    }

    finally

    {

    Baglanti.Kapat();

    }

     

    And here is what i have there in Baglanti class;

     

    public class Baglan

    {

    private bool fActive;

    private OleDbConnection fConnection;

    private OleDbTransaction fTransaction;
    public Baglan()

    {

    //

    // TODO: Add constructor logic here

    //

    }

    public void Ac()

    {

    if (fActive)

    throw new Exception("Connection is already open");

    fConnection = new OleDbConnection();

    fConnection.ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0; Data source=  ... \Veri_1.mdb";

    try

    {

    fConnection.Open();

    fTransaction = fConnection.BeginTransaction();

    fActive =
    true;

    }

    catch

    {

    fActive =
    false;

    }

    finally

    {

    }

    }

    public void Kapat()

    {

    if (!fActive)

    throw new Exception("Connection is already closed");

    fActive = false;

    fTransaction.Dispose();

    fConnection.Close();

    fConnection.Dispose();

    fConnection =
    null;GC.Collect();

    }

    public OleDbConnection Connection

    {

    get

    {

    return fConnection;

    }

    }

    public OleDbTransaction Transaction

    {

    get

    {

    return fTransaction;

    }

    }

    public bool Active

    {

    get

    {

    return fActive;

    }

    set

    {

    if (value != fActive)if (value)

    Ac();

    else

    Kapat();

    }

    }

    }

    Friday, March 27, 2009 4:55 AM

Answers

  • User-1659704165 posted

    Hi,

    U have code as Below

    /*
    return "başarılı";
    fSONUC = dt

    */
    Y donot U

    Use
    /*
    fSONUC = dt
    return "başarılı";

     

    */

    Hope it helps

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, March 27, 2009 8:59 AM

All replies

  • User-1659704165 posted

     Hi,

    http://weblogs.asp.net/rosherove/archive/2004/01/22/61541.aspx
    http://www.windowsitlibrary.com/Content/1205/06/3.html

    Check Above Link

    Hope It helps

    Friday, March 27, 2009 5:03 AM
  • User-388731848 posted

     Hi,

    http://weblogs.asp.net/rosherove/archive/2004/01/22/61541.aspx
    http://www.windowsitlibrary.com/Content/1205/06/3.html

    Check Above Link

    Hope It helps

    Well actually, i don't wantto convert my DataReader into a DataSet.

    Friday, March 27, 2009 5:19 AM
  • User-1659704165 posted

    Hi,

    U have code as Below

    /*
    return "başarılı";
    fSONUC = dt

    */
    Y donot U

    Use
    /*
    fSONUC = dt
    return "başarılı";

     

    */

    Hope it helps

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, March 27, 2009 8:59 AM